Skip to content
Advertisement

How can I send a message to a specific channel by using my own “say” command in discord.js?

I tried to make a code like I write .say blabla” in another channel and It will delete my channel and send my message to “#general” but I can’t find a code to do this.

client.on('message', message => {
    if (message.content.startsWith(prefix + 'ç')) {
        if (message.author.bot) return;
        message.delete()
        const SayMessage = message.content.slice(2).trim();
        message.channel.send(SayMessage)

Here is the code. Can you help me?

Advertisement

Answer

You are doing message.delete() first and then after that, you are doing message.content. In this case, the message.content will be null and you cant send an empty message. So first assign the message content to SayMessage and then delete the message. Also if you need to send to another specific channel, you need to get the channel, and then send it there.

Eg:

if (message.author.bot) return;
if (message.content.startsWith(prefix + 'ç')) {
        const SayMessage = message.content.slice(2).trim();
        message.delete();
        const Mchannel = message.guild.channels.cache.get('the-channel-id');
        Mchannel.send(SayMessage);
}

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement