简体   繁体   English

Discord Bot在发送消息时出错

[英]Error with discord bot on sending message

I'm getting this strange error on adding this sending message with the discord Bot. 我在与不和谐的Bot添加此发送消息时遇到了这个奇怪的错误。 I was following the Scratch Tutorial & everything went fine except this when I try to send a message on bot active. 我一直在按照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');

Result:- 结果:-

`(node:8480) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Access at C:\\Users\\Deepanshu\\node_modules\\discord.js\\src\\client\\rest\\RequestHandlers\\Sequential.js:85:15 at C:\\Users\\Deepanshu\\node_modules\\snekfetch\\src\\index.js:215:21 at processTicksAndRejections (internal/process/task_queues.js:85:5) (node:8480) UnhandledPromiseRejectionWarning: Unhandled promise rejection. `(node:8480)UnhandledPromiseRejectionWarning:DiscordAPIError:C:\\ Users \\ Deepanshu \\ node_modules \\ discord.js \\ src \\ client \\ rest \\ RequestHandlers \\ Sequential.js:85:15在C:\\ Users \\ Deepanshu \\ node_modules缺少访问权限\\ snekfetch \\ src \\ index.js:215:21在processTicksAndRejections(内部/进程/task_queues.js:85:5)(节点:8480)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。 This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). 引发此错误的原因可能是抛出了一个没有catch块的异步函数,或者是拒绝了一个.catch()无法处理的承诺。 (rejection id: 2) (node:8480) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. (拒绝标识:2)(节点:8480)[DEP0018] DeprecationWarning:不建议使用未处理的承诺拒绝。 In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程。 (node:8480) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions at C:\\Users\\Deepanshu\\node_modules\\discord.js\\src\\client\\rest\\RequestHandlers\\Sequential.js:85:15 at C:\\Users\\Deepanshu\\node_modules\\snekfetch\\src\\index.js:215:21 at processTicksAndRejections (internal/process/task_queues.js:85:5) (node:8480) UnhandledPromiseRejectionWarning: Unhandled promise rejection. (node:8480)UnhandledPromiseRejectionWarning:DiscordAPIError:C:\\ Users \\ Deepanshu \\ node_modules \\ discord.js \\ src \\ client \\ rest \\ RequestHandlers \\ Sequential.js:85:15在C:\\ Users \\ Deepanshu \\ node_modules \\中缺少权限在processTicksAndRejections(内部/进程/task_queues.js:85:5)(节点:8480)处的snekfetch \\ src \\ index.js:215:21(node:8480)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。 This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). 引发此错误的原因可能是抛出了一个没有catch块的异步函数,或者是拒绝了一个.catch()无法处理的承诺。 (rejection id: 4) (拒绝ID:4)

I have copied your code and tried it, and it works perfectly fine. 我已经复制了您的代码并进行了尝试,并且效果很好。 So the problem must be with some of your permissions, as shown by the error. 因此,问题一定出在您的某些权限上,如错误所示。 Maybe the mainChannel that you're trying to send a message doesn't allow messages to be sent from the bot. 也许您试图发送消息的mainChannel不允许从机器人发送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM