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

LevelUp event #1

Closed
NotSoMik opened this issue Jul 23, 2022 · 30 comments
Closed

LevelUp event #1

NotSoMik opened this issue Jul 23, 2022 · 30 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@NotSoMik
Copy link

Can you give a better example about the level up event since there is the same example on the documentation and Im not sure what to do

@Abadima Abadima added the documentation Improvements or additions to documentation label Jul 23, 2022
@Abadima
Copy link
Owner

Abadima commented Jul 23, 2022

Hello! As shown in my index.js file, I have enlisted

client.on('levelUp', async (message, data, role) => { your_code_here })

this is basically just a callback function, whenever the user levels up, as long as you have that code somewhere, it will trigger the event, allowing you to proceed however you wish!

If I was able to help, you may close the issue, otherwise please let me know how I should explain :)

@NotSoMik
Copy link
Author

NotSoMik commented Jul 23, 2022

Thanks for this info so something like

const xp = require("simply-xp");
const client = require("..");

client.on("levelUp", async (message, data) => {
    message.channel.send({
        content: `🥳 <@${data.userID}>, **Level Up! 🎉** Now you are **level ${data.level}** in **${message.guild.name}**.`
    });
// if the user levels up gets a role, right?
    xp.lvlRole(message, data.userID, data.guildID);
    return;
})
will be fine?

@Abadima
Copy link
Owner

Abadima commented Jul 23, 2022

Yep! That should work

@NotSoMik
Copy link
Author

NotSoMik commented Jul 23, 2022

Ok cool, if the user gets the role how can i add an extra message? Like the normale message will be

🥳 <@${data.userID}>, **Level Up! 🎉** Now you are **level ${data.level}** in **${message.guild.name}**.`
    });

and if the user get a role after it reaches a certain level the bot should add a text like: You got this role etc

@Abadima
Copy link
Owner

Abadima commented Jul 23, 2022

It's possible! role is listed in the callback when the user levels up (using addXP method)

So you can just do something like this:

client.on("levelUp", async (message, data, role) => {
   // level up message goes here
   
   if (role != undefined) {
     <Channel>.send(`Hey! You have also received the following roles: ${<@&role.role>}`)
     <xp>.lvlRole(message, data.userID, data.guildID)
})

Which allows you to check if there are roles for the new level

TIP: role returns something along the lines of: { lvl: 5, role: "role-id" }

@Abadima Abadima added the question Further information is requested label Jul 23, 2022
@NotSoMik
Copy link
Author

That's amazing, ty for your help. I'll open this issue when I'll have other questions :)

@NotSoMik NotSoMik reopened this Jul 24, 2022
@NotSoMik
Copy link
Author

yo I got another question lol, if i use all the functions of simply-xp what intent should I put? Only guild and guild messages?

@Abadima
Copy link
Owner

Abadima commented Jul 24, 2022

For my test bot, I've only used the Guild intent for all functions!

It really depends on how you're using them. If it works, then you should be alright

@NotSoMik
Copy link
Author

Ok cool but is there a way we can customize this

if (!user) throw new Error('[XP] NO_DATA | User has no XP data.')

Because as you know if a user has no xp it will throw that error, so how can we avoid that

@Abadima
Copy link
Owner

Abadima commented Jul 24, 2022

There isn't a way to change it @ core, HOWEVER! You can actually avoid this by using <xp>.fetch(), if the user is found, then use the rank function

If the user is NOT found, then you can use <xp>.create(client, userid, guildid) & then run rank(), that way you completely avoid that error

@NotSoMik
Copy link
Author

Nice, when I'll be free I'll send ex example and you can tell me if its correct

@NotSoMik NotSoMik reopened this Aug 9, 2022
@NotSoMik
Copy link
Author

NotSoMik commented Aug 9, 2022

If I want to get more xp on Saturday and normal xp on the other days, something like this willl be fine, right?

const date = new Date();
if (date.getDay() === 6)
            xp.addXP(message, message.author.id, message.guild.id, {
                min: 20,
                max: 35,
            });
        else
            xp.addXP(message, message.author.id, message.guild.id, {
                min: 1,
                max: 15,
            });
// I'm using this in my messageCreate event so I need the guild messages intent

also how can I get in the console the amount of xp that an user gets

@Abadima
Copy link
Owner

Abadima commented Aug 9, 2022

Good day! Thank you for your patience; the code you gave should function as intended. Regarding the XP logging, you can see that it does so at Our Guide!, so you'll just need to return it, something like:

xp.addXP(message, userid, guildid, { .. }).then(res => { console.log(res) })
// or you can also do this
var res = await xp.addXP(message, userid, guildid, { ... })
console.log(res)

Both of them should return something like { xp: 15 }

@NotSoMik
Copy link
Author

NotSoMik commented Aug 9, 2022

Oh thanks a lot

@NotSoMik
Copy link
Author

NotSoMik commented Aug 9, 2022

Since there is a rank card will you ever make a leaderboard card where are displayed the top 10 people

@Abadima
Copy link
Owner

Abadima commented Aug 9, 2022

Although we do not currently have a leaderboard card, that is an interesting thought! I'll add it to my to-do list; I might introduce it in v2! In the meantime, you can still set a limit of 10 people by following the steps on Our Documentation if you haven't already known :D

@NotSoMik
Copy link
Author

NotSoMik commented Aug 9, 2022

yea I know how to make it but it will be cool if you add that :)

@NotSoMik NotSoMik closed this as completed Aug 9, 2022
@NotSoMik NotSoMik reopened this Aug 16, 2022
@NotSoMik
Copy link
Author

It's possible! role is listed in the callback when the user levels up (using addXP method)

So you can just do something like this:

client.on("levelUp", async (message, data, role) => {
   // level up message goes here
   
   if (role != undefined) {
     <Channel>.send(`Hey! You have also received the following roles: ${<@&role.role>}`)
     <xp>.lvlRole(message, data.userID, data.guildID)
})

Which allows you to check if there are roles for the new level

TIP: role returns something along the lines of: { lvl: 5, role: "role-id" }

Hello again! About that, if I set more roles at the same level, the bot adds them but sends a message saying that it has only added one role, how can I fix that :)

@Abadima
Copy link
Owner

Abadima commented Aug 16, 2022

Hey there! Can you provide some logs, and the message it's saying? I'll look further into this matter.

@NotSoMik
Copy link
Author

Sure, hope its clear
Screenshot_20220816-233025_Discord

@NotSoMik
Copy link
Author

I got both roles tho

@Abadima
Copy link
Owner

Abadima commented Aug 17, 2022

Assuming you're fetching the role(s) from the levelUp event, I might be able to crack down the issue, please hold! I'll reply as soon as possible.

@NotSoMik
Copy link
Author

Sure, take your time

@Abadima
Copy link
Owner

Abadima commented Aug 17, 2022

Hey There! I've identified the bug and fixed it:
I just need to make sure that all of the other fixes are working properly before I release the next update.

@NotSoMik
Copy link
Author

Good job, so that was a bug, right?

@Abadima
Copy link
Owner

Abadima commented Aug 17, 2022

Yeah! A minor mistake was made in earlier versions of the package.

@NotSoMik
Copy link
Author

Oh ok, feel free to close this issue

@Abadima
Copy link
Owner

Abadima commented Aug 17, 2022

Hello once more! Simply-XP has just been updated to v1.3.4, which includes all the most recent updates and a few more minor changes that I think you'll like.

@Abadima Abadima closed this as completed Aug 17, 2022
@NotSoMik
Copy link
Author

Hello I got another issue
Screenshot_20220817-161016_Discord

if (role != undefined) {
            message.channel.send({
                content: `Hey! You have also received the following roles: <@&${role.role}>`,
            });
            xp.lvlRole(message, data.userID, data.guildID);
        }

@NotSoMik
Copy link
Author

With the new version @Abadima

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants