0

I have a command where it asks a question and gives different responses based on the answer, and that part works, but the command doest end, meaning that if you reply to a new instance of the command, the first instance and the new instance will reply. I tried different timeout functions but nothing worked. here's the code:

module.exports = {
name: 'test',
description: "test comand",
execute(message, args, Discord) {
    message.channel.send("Do you want to test this command?\n `Yes`, `No` or `Mayhaps`")
    console.log(message.author.id)
    const collector = new Discord.MessageCollector(message.channel, m => m.author.id === member, { time: 10000 });
    collector.on('collect', message => {
        if (message.content.toUpperCase() == "YES") {
            message.channel.send("Let's Go! It worked!");
    } else if (message.content.toUpperCase() == "NO") {
            message.channel.send( "Task failed successfully.");
     } else if (message.content.toUpperCase() == "MAYHAPS") {
            message.channel.send("ERROR: IT WORKED ANYWAY");
        }
})
}

}

1 Answer 1

2

I think the problem is that you are not stopping the collector, try:

collector.stop();

after all the conditions.

Also, you need to check that the message sent is from a user and not from the bot, since you are not awaiting the first message to send before starting the collector.

message.channel.send("Do you want to test this command?\n `Yes`, `No` or `Mayhaps`")

The colletor is collecting that message, which is from the bot, so you are stopping the collector with the bot message, not giving a chance to reply.

Final result:

collector.on("collect", async (message) => {
    if (message.content.toUpperCase() == "YES") {
        await message.channel.send("Let's Go! It worked!");
    } else if (message.content.toUpperCase() == "NO") {
        await message.channel.send("Task failed successfully.");
    } else if (message.content.toUpperCase() == "MAYHAPS") {
        await message.channel.send("ERROR: IT WORKED ANYWAY");
    }
    if (!message.author.bot) collector.stop();
});

In case you don't want to check if the message is from a bot, you can await the first message like this:

module.exports = {
    name: 'test',
    description: "test comand",
    async execute(message, args, Discord) {
        await message.channel.send("Do you want to test this command?\n `Yes`, `No` or `Mayhaps`")
        console.log(message.author.id)
        const collector = new Discord.MessageCollector(message.channel, m => m.author.id === member, { time: 10000 });
        collector.on('collect', message => {
            if (message.content.toUpperCase() == "YES") {
                message.channel.send("Let's Go! It worked!");
            } else if (message.content.toUpperCase() == "NO") {
                message.channel.send( "Task failed successfully.");
            } else if (message.content.toUpperCase() == "MAYHAPS") {
                message.channel.send("ERROR: IT WORKED ANYWAY");
            }
        })
    }
}
Sign up to request clarification or add additional context in comments.

10 Comments

When I add that, the part of the command in the collector, ie, the response, doesn't work.
You may need to make it async and await the send commands
How do I do that? Sorry but I'm new to coding and don't know much. Thanks for all the help!
I've just edited the answer, try that code.
It still doesn't seem to work. When I reply with yes, nothing happens
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.