1
votes

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...

1
You can find all the members of an role and make a foreach to all members in that roleCursed
I understand how to do that but what I don't get is how to send the message to the role member through the reply method.LucasF
on a foreach you will have the member promise and you can make member.replyCursed
You're asking an XY question. Why bother using msg.reply here if it's not going to be of any use to you? The accepted answer at the proposed duplicate does exactly what you need, you just need to put it in a client.on("message", msg => {...}); call, and get the guild from message.guild or whatever.Ruzihm

1 Answers

3
votes

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.