I wrote a bot that echoes the messages that are sent by users of a discord guild. However, the bot also echoes the replies sent after an interaction. I would expect it to be the same user as the client but it is not. I only tested with slash commands but it may be same for other interactions.
Code sample
// When a message is sent
client.on('messageCreate', async (message) => {
// Do nothing if message coming from it self
if (message.author == client.user) return;
// message.author == client.user returns false when bot replies with Pong!
// Echoing message
message.channel.send(message.content);
});
// Bot Commands
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName == 'ping') {
await interaction.reply('Pong!');
}
});
You shouldn't compare two class instances with an equality operator as this is very likely to produce wrong results, especially when using lazy comparisons. You should compare the IDs instead.
Which package is this bug report for?
discord.js
Issue description
I wrote a bot that echoes the messages that are sent by users of a discord guild. However, the bot also echoes the replies sent after an interaction. I would expect it to be the same user as the client but it is not. I only tested with slash commands but it may be same for other interactions.
Code sample
Package version
13.7.0
Node.js version
18.3.0
Operating system
Linux Arch
Priority this issue should have
Low (slightly annoying)
Which partials do you have configured?
Message
Which gateway intents are you subscribing to?
Guilds, GuildMessages
I have tested this issue on a development release
No response