I want to send a message on a specific channel. but the thing is my command should be like this +post CHANNELID message then it will post the message on this channel that I've put the id. so can anyone help me to do that??
Asked
Active
Viewed 194 times
0
-
Does this answer your question? [Send a message with Discord.js](https://stackoverflow.com/questions/45120618/send-a-message-with-discord-js) – MrMythical Aug 18 '21 at 04:15
-
Does this answer your question? [Discord.js sending a message to a specific channel](https://stackoverflow.com/questions/52258064/discord-js-sending-a-message-to-a-specific-channel) – Lauren Yim Aug 19 '21 at 11:34
1 Answers
0
This is pretty simple actually. There are a few things you need to do.
- Separate the arguments
- Find channel with first argument (id)
- Send message to the channel with content of other arguments joined with spaces
This is a working example of your command
client.on("message", msg => {
const args = msg.content.split(' ');
const [, chanId, ...message] = args;
const channel = msg.guild.channels.resolve(chanId);
channel.send(message.join(" "))
})

MrMythical
- 8,908
- 2
- 17
- 45