我无法使我的机器人联机,它显示TypeError[CLIENT_MISSING_INTENTS](vscode)


const Discord = require("discord.js");
const Bot = new Discord.Client({Intents:[Discord.Intents.FLAGS.GUILD_MEMBERS, Discord.Intents.FLAGS.GUILDS]})
Bot.on('ready', () => {
console.log("The bot is online") 
let commands = Bot.application.commands;
commands.create({
name: "hello" ,
description: "reply hello to the user",
options: [
{
name: "person",
description: "The user you want to say hello to",
require: true,
type: Discord.Constants.ApplicationCommandOptionTypes.USER
}
]
})
})

Bot.on('interactionCreate', interaction => {
if(!interaction.isCommand()) return;
let name  = interaction.commandName
let options = interaction.options;
if(name == "hello") {
interaction.reply({
content: "Hello",
ephemeral: false
})
}
if(name == "sayhello"){
let user = options.getUser('person');
interaction.reply({
content: 'Hello ${user.username}
})
}
})
bot.login("token")

intentsis选项为小写,而非大写。参见ClientOptions

实际上,由于新的discord.js更新,您需要向机器人程序提供意图。这可能有助于

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

由于discord.jsv13,在声明客户端时需要提供Intents。Discord引入了它们,这样开发者就可以选择机器人需要接收什么类型的数据。您所要做的就是在声明客户端时添加意图。代码可能看起来像这样:

const { Client } = require('discord.js')
const client = new Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES
]
})

此外,正如@Richie Bendall所指出的,您在声明意图时已将I大写。你可以在这里了解更多关于意图的信息=>Gateway Intents|Discord.js

相关内容

最新更新