我如何让我的discord.js机器人在其他渠道中进行读写?

时间:2020-05-26 10:45:19

标签: node.js discord.js

这是代码:

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

client.once('ready', () => {
    console.log('Ready!');
});
client.on('message', message => {
    if (message.content === '!ping') {
    // send back "Pong." to the channel the message was sent in
    message.channel.send('Pong.');
}
});

client.login('');

它在主通道中工作正常,但是,当我从另一个通道调用它时,会发生此错误:

(node:8620) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
    at RequestHandler.execute (C:\Users\epopova1\Desktop\poserBot\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:8620) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8620) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

有帮助吗?

1 个答案:

答案 0 :(得分:0)

此错误是因为您的机器人无需获得服务器的适当权限即可执行您想要的功能。

从服务器中启动您的机器人。然后,您可以将漫游器邀请链接放入浏览器中。 看起来像这样:

https://discord.com/api/oauth2/authorize?client_id=708381241052546648

上面说的是邀请您的漫游器的链接。

切断链接中的所有内容,直到/除非它看起来像这样:

https://discord.com/api/oauth2/authorize?client_id=708351240052146248

然后将其附加到链接的末尾:

&permissions=68608&scope=bot

因此,作为示例,您的链接将如下所示:

https://discord.com/api/oauth2/authorize?client_id=7083819999999648&permissions=68608&scope=bot

这将为机器人提供执行上述代码所需的一切。