Home > Software design >  Bot giving ranks for correct answers
Bot giving ranks for correct answers

Time:03-17

My bot needs to respond to !rank (rank name) in the #bot-commands channel and when someone needs a rank it asks questions about the game and if the answer is correct the rank is given My code (I am a beginner):

 client.on("messagecCreate"), message => {
    if (message.conetent === '!rank lol') {
        message.channel.send('Can Yuumy go TOP lane?   ---  Respond with "yes" or "no" !')
        msg.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })
          .then(collection => {
        let replyMessage = collection.first() //the message you wanted to obtain
        if (replyMessage.content == 'no') {
            var role = message.guild.roles.find(role => role.name === "LOL");
            message.member.addRole(role);

        }
        })
    }
}

CodePudding user response:

Use this code:

client.on('messageCreate', message => {
    if (message.conetent === '!rank lol') {
        message.channel.send('Can Yuumy go TOP lane?   ---  Respond with "yes" or "no" !');
        const filter = (msg) => msg.author.id === message.author.id && ['yes', 'no'].includes(msg.content.trim().toLowerCase()); // filter for messages collection
        message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })
            .then(collection => {
                const replyMessage = collection.first(); // the message you wanted to obtain
                if (replyMessage.content == 'no') {
                    const role = message.guild.roles.find(r => r.name === 'LOL');
                    message.member.roles.add(role); // add the role to member
                }
            });
    }
});

CodePudding user response:

It seems you're using discord.js v13, there's alot of missed type lines such as 'messagecCreate' => 'messageCreate', 'message.conetent => message.content'.

since you're using

client.on('messageCreate', message)

on this code line:

msg.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] }) 

change it into

message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })

In your code line:

var role = message.guild.roles.find(role => role.name === "LOL");
message.member.addRole(role);

change to:

var role = message.guild.roles.find(role => role.name === "LOL");
message.member.roles.add(role);
  • Related