为什么我收到这个错误 ReferenceError: channel is not defined

时间:2021-04-06 21:16:11

标签: javascript node.js discord discord.js

这只是一个测试命令,所以它并不重要,但我想知道为什么会发生这个错误我认为它与 channel.send 有关系,但这毫无意义,我很困惑已经为此工作了一个小时,所以如果有人能帮助我,那就太棒了。

这是收到错误的代码

const config = require('../config.json');
const fs = require('fs');

module.exports = {
  name: "test",
  aliases: ["test"],
  description: "test lmfao",
  category: "test",
  execute(message, args) {
    const embed = new Discord.MessageEmbed()
      .setColor('#0099ff')
      .setTitle('test')
      .setURL('https://discord.js.org/')
      .setAuthor('test', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
      .setDescription('test')
      .setThumbnail('https://i.imgur.com/wSTFkRM.png')
      .addFields(
        { name: 'test', value: 'test', inline: false },
      )
      .setImage('https://i.imgur.com/wSTFkRM.png')
      .setTimestamp('timestamp')
      .setFooter('test', 'https://i.imgur.com/wSTFkRM.png');
    
      channel.send(embed);
  },
};

如果你需要,这里是完整的错误

    at Object.execute (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\commands\Test.js:25:7)
    at Client.<anonymous> (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\index.js:73:21)   
    at Client.emit (node:events:369:20)
    at MessageCreateAction.handle (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)    
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)   
    at WebSocketShard.onMessage (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)  
    at WebSocket.onMessage (C:\Users\boble\OneDrive\Desktop\ScriptsNStuff\karmik\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (node:events:369:20)

1 个答案:

答案 0 :(得分:1)

代替:

channel.send(embed);

使用:

message.channel.send(embed)

channel 未声明,我猜您想将消息发送到已发送消息通道。