discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.23k stars 3.96k forks source link

Replies for interactions has different author than the client #8142

Closed hi563145 closed 2 years ago

hi563145 commented 2 years ago

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

// 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!');
  }
});

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

ImRodry commented 2 years ago

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.