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

问题描述 投票:0回答:1

这里是代码:

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.

有帮助吗?

node.js discord.js
1个回答
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

这将使bot具备执行上述代码所需的一切。

© www.soinside.com 2019 - 2024. All rights reserved.