Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canvacord example is outdated #72

Open
twlite opened this issue Jan 8, 2024 · 1 comment
Open

canvacord example is outdated #72

twlite opened this issue Jan 8, 2024 · 1 comment
Assignees
Labels
being worked on enhancement New feature or request

Comments

@twlite
Copy link

twlite commented Jan 8, 2024

👋 canvacord has reached v6 which comes with breaking changes, also moving away from canvas for image generation for flexibility and it means that existing examples dont really work anymore.

Here is an example on how use builtin xp card builder in v6. While I am not familiar with discord.js, this example is based on the previous example mentioned in this repository.

const { RankCardBuilder, Font } = require('canvacord');

// place it outside of the command function
Font.loadDefault(); // or load your own font!

const target = message.mentions.users.first() || message.author; // Grab the target.

const user = await Levels.fetch(target.id, message.guild.id, true); // Selects the target from the database.

const rank = new RankCardBuilder() // Build the Rank Card
    .setAvatar(target.displayAvatarURL({format: 'png', size: 512}))
    .setCurrentXP(user.cleanXp) // Current User Xp for the current level
    .setRequiredXP(user.cleanNextLevelXp) //The required Xp for the next level
    .setRank(user.position) // Position of the user on the leaderboard
    .setLevel(user.level) // Current Level of the user
    .setUsername(target.username)
    .setDisplayName(target.displayName);

rank.build({ format: 'png' })
.then(data => {
    // consume the image
});

For flexibility, canvacord now has setProgressCalculator to determine the width of the progress bar.

.setProgressCalculator(() => {
  return Math.floor(Math.random() * 100); // return random width (0-100)
})
@Myst82015 Myst82015 self-assigned this Jan 16, 2024
@Myst82015 Myst82015 added enhancement New feature or request being worked on labels Jan 16, 2024
@Myst82015
Copy link
Collaborator

👋 Thanks for the heads-up.

Just looked at the docs of canvacord, they definitely changed it.
I'll update our docs of discord-xp when I have some spare time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
being worked on enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants