javascriptnode.jsdiscorddiscord.js

Pinging a role with discord js v14


I am trying to ping a role with discord.js; not just displaying the role name but sending a notification to all members with the role.

I have tried

await interaction.reply({
  embeds: [embed],
  components: [row],
  content: `<@&${team.id}>`,
  allowed_mentions: {
    roles: [`${team.id}`]
  }
});

I don't know if I have to place "allowed_mentions" in a different place or just to not use it. Perhaps I did not use it correctly.

I have also tried looking on my Discord settings. I placed my role on pingable by everyone, allowing the bot to ping everyone and the role assigned to the bot to ping everyone, but nothing changed.


Solution

  • You cannot mention other users or roles when responding to an interaction and I don’t believe there are any ways to override this behaviour. You must first defer the interaction for Discord, and then send the message content with the mentions as a message in the channel.

    await interaction.deferUpdate();
    await interaction.channel.send({
      content: `<@&${team.id}>`,
      embeds: [embed],
      components: [row],
    });