Skip to content
Advertisement

How can I get my bot to send a message to another channel?

so I have a bot that takes whatever I say when I do the command /say and deletes my message. Since it still technically sends my message, people will see it through notifications and can tell that it was me that got the bot to send the text. I am doing this as a fun and troll thing with my friends so I wanted to figure out a way for the bot to take my /say command from a hidden text channel and put it in the general channel.

const Discord = require('discord.js') //Discord package
const client = new Discord.Client(); //New Discord Client
const prefix = '/'; //command prefix


client.on('ready', () => {
    console.log('Bot is Online.');
});

client.on('message', message => {

    if(message.member.roles.find('name', 'Bot')){ //only role 'Bot' can use the command

        if (message.author.bot) return undefined; //bot does not reply to itself

        let msg = message.content.toLowerCase();
        let args = message.content.slice(prefix.length).trim().split(' '); //arguments
        let command = args.shift().toLowerCase(); //shifts args to lower case letters

        if (command === 'say'){

         let say = args.join(' '); //space
         message.delete(); //deletes the message you sent
         message.channel.send(say);
       
        }
    }
});

This is my code so far and I’ve got it working for what I want it to do. I just need help with how to get it to copy a hidden channel’s message to the general channel

Advertisement

Answer

Assume you have some channel named general.

The following will send a message to it:

client.on('message', message => {

  if (message.author.bot) return undefined //bot does not reply to itself

  let msg = message.content.toLowerCase()
  let args = message.content
    .slice(prefix.length)
    .trim()
    .split(' ') //arguments
  let command = args.shift().toLowerCase() //shifts args to lower case letters

  if (command === 'say') {
    let say = args.join(' ') //space
    message.delete() //deletes the message you sent
    const generalChannel = message.guild.channels.find(channel => channel.name === "general")
    generalChannel.send(say)
  }
})
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement