我正在创建一个不和谐的机器人,这发生了

时间:2020-03-28 19:10:28

标签: javascript discord

这是我在bot.js上遇到的代码:

client.on('message', msg => {
  if (msg.content === 'r!play luigi nutting') {
   const channel = Yee.channels.cache.get('general');
   channel.send('r!skip');
  }
});

命令提示符说:

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)``

(在上下文中,我创建了该漫游器是因为有人在垃圾邮件中发送了垃圾邮件,但我不想禁止它们)

1 个答案:

答案 0 :(得分:1)

好了,所以错误就在这里:const channel = Yee.channels.cache.get('general');

您需要指定客户端,在这种情况下,它已经是您在顶部定义的客户端“ const client = new Discord.Client();”。 因此,要获得一个ID为client.channels.get("ChannelID");的频道 并获得具有名称的频道:

client.channels.find(channel => channel.name == "General");