Yahmo
Yahmo

Reputation: 5

How do give only person that write i an specific discord channel xp

Here is the Code. I only want to give members xp when they write in a specific discord channel. How can i do that?

client.on('messageCreate', async message => {
      if (!message.guild) return;
      if (message.author.bot) return;
      
      const prefix = '?'
    
      const args = message.content.slice(prefix.length).trim().split(/ +/g);
      const command = args.shift().toLowerCase();
      const user = await Levels.fetch(message.author.id, message.guild.id);
      if (!message.guild) return;
      if (message.author.bot) return;
      
      const randomAmountOfXp = Math.floor(Math.random() * 29) + 1; // Min 1, Max 30
      const hasLeveledUp = await Levels.appendXp(message.author.id, message.guild.id, randomAmountOfXp);
      if (hasLeveledUp) {
        const user = await Levels.fetch(message.author.id, message.guild.id);
        message.channel.send({ content: `${message.author}, congratulations! You have leveled up to **${user.level}**. :tada:` });
       }
       if (user.level === 5) {
        message.member.roles.add("1022876270754791445"); 
       } else if (user.level === 10) {
        message.member.roles.add("1022876505132499054");
       }else if (user.level === 10) {
        message.member.roles.remove("1022876270754791445");
       }
        });

Upvotes: 0

Views: 37

Answers (1)

Alpha
Alpha

Reputation: 187

You can check message's channel id when event triggered.

if (message.channel.id !== "CHANNEL_ID") return;

Upvotes: 1

Related Questions