Reputation: 176
I am developing the following command: ! sir snd all -hello
This command tells you to send the message after the "-" to all channels on the server where the command is sent.
This is what I have done so far:
else if(command == 'snd'){
if(suffix == 'all'){
client.channels.cache.forEach( channel => {
if(channel.type == "GUILD_TEXT") {
channel.send(sParameter[1])
}
});
}
}
The problem is that the following line of code:
client.channels.cache.forEach
It takes all the channels that the bot is part of; I would like to take only the channels of the server in which the message is sent.
In fact now, if I go to send that command, a message will be sent to all the text channels of all the servers of which the bot is part
Is there a solution to this? So to take the ids of the channels of the server where the command is sent?
Upvotes: 0
Views: 53
Reputation: 2286
You may simply get all the channels of the guild instead of all channels. Like so:
message.guild.channels.cache.forEach( channel => {
if(channel.type == "GUILD_TEXT") {
channel.send(sParameter[1])
}
});
Upvotes: 1