Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送消息时出现discord bot错误_Javascript_Node.js - Fatal编程技术网

Javascript 发送消息时出现discord bot错误

Javascript 发送消息时出现discord bot错误,javascript,node.js,Javascript,Node.js,我在使用discord机器人添加此发送消息时遇到了一个奇怪的错误。我在遵循Scratch教程&当我尝试在bot-active上发送消息时,一切都很顺利 const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); client.user.s

我在使用discord机器人添加此发送消息时遇到了一个奇怪的错误。我在遵循Scratch教程&当我尝试在bot-active上发送消息时,一切都很顺利

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);

  client.user.setActivity('You', {type: 'WATCHING'});

  var mainChannel = client.channels.get('51549559XXXX')
  mainChannel.send("Hello, world!")
});

client.on('message', (received) => {
 if (received.author == client.user) {
    return
}
    received.channel.send("You: " + received.content);
});  

client.login('TOKEN');
结果:-

`(节点:8480)未经处理的PromisejectionWarning:DiscordAPIError:缺少访问 位于C:\Users\Deepanshu\node\u modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15 在C:\Users\Deepanshu\node\u modules\snekfetch\src\index.js:215:21 在处理和拒绝时(内部/process/task_queues.js:85:5) (节点:8480)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:2) (节点:8480)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。 (节点:8480)未处理的PromisejectionWarning:DiscordAPIError:缺少权限 位于C:\Users\Deepanshu\node\u modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15 在C:\Users\Deepanshu\node\u modules\snekfetch\src\index.js:215:21 在处理和拒绝时(内部/process/task_queues.js:85:5)
(节点:8480)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:4)

我已经复制了你的代码并试用过,效果非常好。因此,问题一定出在您的某些权限上,如错误所示。可能您尝试发送消息的主通道不允许从bot发送消息