TechnoPhoenix
TechnoPhoenix

Reputation: 35

TypeError: channel.send is not a function (Deprecated?)

Im trying to build a discord bot but I need to send a message to a specific channel. I've given it 100 tries but keep getting:

TypeError: bot.channels.fetch(...).send is not a function.

Everywhere I read, I see "use channel.send()" but I cannot find an actual fix for my problem. Is channel.send() deprecated? Heres the line that the error throws an error on:

bot.channels.fetch(id).send(message);

I know channels.get() was depricated and when using .fetch(id), I get the channel object however it wont let me send the message. ANY help will be appreciated as I have spent days on this alone. Thanks.

Full block of code:

var reportEmbed = new Discord.MessageEmbed()
   .setColor('#0099ff')
   .setTitle('New Report')
   .setAuthor(msg.author.tag)
   .setDescription(reportMessage)
   .setTimestamp();
console.log(bot.channels.fetch('my channel id'));
bot.channels.fetch('my channel id').then(channel => {
   channel.send(reportEmbed);
});

When console logged, I get the correct channel object.

Upvotes: 0

Views: 505

Answers (2)

Lioness100
Lioness100

Reputation: 8412

Try using:

bot.channels.cache.get(id).send(message)

Instead

Upvotes: 1

Dorian349
Dorian349

Reputation: 1589

As I can see in the documentation, the fetch() method returns a promise. (Link)

So, in order to get the channel, you need to use the current code:

bot.channels.fetch("id").then(channel => {
  channel.send(message);
});

Upvotes: 1

Related Questions