Search code examples
discorddiscord.js

bot to send message to a different channel on same server


I am trying to get my Discord bot to send a message to another channel when there is more than one item in the response, write a message to another channel (on the same server). This code is within an async function and returns the first item of the response.

Currently, this code is sending to the channel where the command originated. When I attempt things I've found to send to another channel, I get errors such as fetch not being found or cache not being found. What am I missing to get this to work?

if(response.length > 1)
{
  let returnMessage = 'Items found: " + response.length;

  for(let i = 0; i < response.length; i++)
  {
    let responseString = response[i].toString();
    returnMessage += "\r\n" + responseString.substring(responseString.indexOf('/', 10));
  }

  // send message to another channel here
  message.channel.send("test message"); // this sends the message to the current channel.
}

Solution

  • Here is what I ended up doing, and it appears to be working.

    message.client.channels.cache.get('CHANNEL ID').send('message');