Gab*_*Edu 3 node.js discord discord.js
我试图在成员加入服务器时添加角色,但它说我没有该权限。如何添加机器人的所有意图/权限?
我将只保留代码的开头。
// Require the necessary discord.js classes
const { Client, Intents, Message } = require('discord.js');
const { Player } = require("discord-player");
const { token, prefix } = require("./config.json");
// Create a new client instance
const client = new Client(
{
restTimeOffset: 0,
shards: "auto",
intents: [
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_SCHEDULED_EVENTS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_WEBHOOKS,
]
});
Run Code Online (Sandbox Code Playgroud)
小智 5
该错误也可能是由于其他原因造成的。该错误背后的一种解释可能是机器人试图向角色级别高于其自身的成员添加角色。在这种情况下,您必须手动重新排列角色层次结构并将机器人的角色放在顶部。
关于意图:不建议只添加您想要的所有意图。整个意图是开发人员可以选择他们希望机器人接收的数据类型。如果我们只选择所有意图,那么整个概念就会被浪费。如果您仍然想启用所有意图,您可以在 Google 中检查intents calculator,然后复制那里给出的意图值并粘贴,如下所示:
const { Intents, Client } = require("discord.js")
const client = new Client({
intents: new Intents(value) // Insert the value here
})
Run Code Online (Sandbox Code Playgroud)