I'm coding a discord Bot with the discord.js library on a nodeJs server. Here is my question: is that possible when an event occure (like someone sending a message) that the bot answers to members of a role, or to everyone. The message.reply("my reply") method only answer to the author of the message as I use it for now...
Your problem is that message.reply()
is a very limited method: it always mentions the author of the message, and you can't override that.
You need to use a more generic method, channel.send()
, and construct the mention yourself. .reply()
is just a shortcut for a frequently used form of it, but you need something custom.
Presumably, you want it to happen in the same channel as the message, so you need message.channel.send("Whatever content you want")
.
Now, to add a role, you need to decide how to pick one. Is it fixed? Then you could hard-code a role mention by role ID : <@&134362454976102401>
(of course, it needs to be the role ID you require).
If you want to find a role, for example by name, you need to do that via searching through the guild in question. You can access it though message.guild
, but be warned that it will be undefined for DMs.
Then you can do something like
const role = message.guild.roles.find(role => role.name === "NameYouWant");
message.channel.send(`${role} something something`);
because Role objects become mentions when converted to strings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.