This is the code I have a problem with on bot.js:
client.on('message', msg => {
if (msg.content === 'r!play luigi nutting') {
const channel = Yee.channels.cache.get('general');
channel.send('r!skip');
}
});
Command prompt says this:
ReferenceError: general is not defined
at Client.<anonymous> (C:\Discord Bot1\bot.js:59:20)
at Client.emit (events.js:327:22)
at MessageCreateHandler.handle (C:\Discord
Bot1\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Discord
Bot1\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:108:65)
at WebSocketConnection.onPacket (C:\Discord
Bot1\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:336:35)
at WebSocketConnection.onMessage (C:\Discord
Bot1\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:299:17)
at WebSocket.onMessage (C:\Discord Bot1\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Discord Bot1\node_modules\ws\lib\websocket.js:789:20)
at Receiver.emit (events.js:315:20)``
(for context I created this bot because someone was spamming something in rythym but I didn't want to ban them)
Alright so the error is here: const channel = Yee.channels.cache.get('general');
You need to specify the client, in this case it's already "client" as you defined it at the top: const client = new Discord.Client();
. So to get a channel with an id: client.channels.get("ChannelID");
And to get a channel with a name:
client.channels.find(channel => channel.name == "General");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.