I had some old code, which I made during V12 of discord.js, which was working correctly. The code failed on me recently upon changing most of the required things to change (things that had changed for v13) and I made a more simplified version to see what the issue was and it seems that the message was sent to the bot, instead of anyone who reacted to the message.
const { client, message } = require("discord.js")
module.exports = {
name: "collect",
description: "--",
category: "info",
async execute(message, args, client) {
const newMsg = await message.channel.send("words")
newMsg.react("✅")
const filter = (reaction, user) => {
return !user.bot
};
const collector = newMsg.createReactionCollector(filter, { time: 6000000 });
collector.on('collect', (reaction, user) => {
user.send("it worked")
});
}
}
This is the code, where I want the bot to create a message, create a reaction below and allow the user to react to it, so it can gain the user's id and send them a message.
However, once I run the code, It sends the message, creates the reaction, and throws back this error below;
DiscordAPIError: Cannot send messages to this user
at RequestHandler.execute (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async UserManager.createDM (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\managers\UserManager.js:58:18)
at async ClientUser.send (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:162:18) {
method: 'post',
path: '/users/852994509628768298/channels',
code: 50007,
httpStatus: 400,
requestData: { json: { recipient_id: '852994509628768298' }, files: [] }
}
The recipient's ID is the same as the bot's ID, so I assume that it is not filtering out the bot's ID with the filter;
const filter = (reaction, user) => {
return !user.bot === message.author.id;
};
Any help would be appreciated, thank you.
Nevermind, I am really dumb
Filter is in the object.
const collector = newMsg.createReactionCollector(filter, { time: 6000000 });
to fix this, I just needed to make it
const collector = newMsg.createReactionCollector({filter, time: 6000000 });