Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  126] [ 2]  / answers: 1 / hits: 150519  / 6 Years ago, sun, july 1, 2018, 12:00:00

I'm trying to send a message to a specific channel with my Discord bot, which is in several servers. I want the bot to pick up on a message from one server and send a message to my personal server, in a specific channel, but I can't get it to 'find' the channel. Has the API changed or something? I tried npm install discord.js to update too.



Code:



if (message.author.id == 'XXXXX' && !mess.includes(Dank) && message.channel.id != 'XXXXX') {
bot.channels.get('XXXXX').send('memes');
}


I tried a few things but none worked.



TypeError: Cannot read property 'send' of undefined
at decideIfMention (C:UsersXXXXDesktopCoding CrudDiscord Bot 2bot.js:80:45)
at Client.bot.on (C:UsersXXXXDesktopCoding CrudDiscord Bot 2bot.js:68:3)
at emitOne (events.js:116:13)
at Client.emit (events.js:211:7)
at MessageCreateHandler.handle (C:UsersXXXXDesktopCoding CrudDiscord Bot 2node_modulesdiscord.jssrcclientwebsocketpacketshandlersMessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:UsersXXXXDesktopCoding CrudDiscord Bot 2node_modulesdiscord.jssrcclientwebsocketpacketsWebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:UsersXXXXDesktopCoding CrudDiscord Bot 2node_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:UsersXXXXDesktopCoding CrudDiscord Bot 2node_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:296:17)
at WebSocket.onMessage (C:UsersXXXXDesktopCoding CrudDiscord Bot 2node_moduleswslibevent-target.js:120:16)
at emitOne (events.js:116:13)

More From » bots

 Answers
28

Assuming you have the client (which would be an instance of Discord.Client) try finding the desired channel by using Client.find:


const channel = client.channels.cache.find(channel => channel.name === channelName)
channel.send(message)

If you don't have the client directly but have a message instance, you could always access it from within the Message.client property.


[#54082] Wednesday, June 27, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carolinabritneyp

Total Points: 75
Total Questions: 102
Total Answers: 105

Location: Armenia
Member since Fri, Apr 16, 2021
3 Years ago
;