英文:
I Try to make a discord bot and I got this error
问题
我制作了一个 Discord 机器人并遇到了这个错误
我试图添加当成员发送“hello”时,机器人回复“hi”
我是根据YouTube上的一个服务器教程来做的。
我遇到了这个错误:
> C:\Users\biket\Desktop\akikloforita\node_modules@discordjs\ws\dist\index.js:1132
> error: new Error("Used disallowed intents")
> ^
>
> Error: Used disallowed intents
> at WebSocketShard.onClose (C:\Users\biket\Desktop\akikloforita\node_modules@discordjs\ws\dist\index.js:1132:18)
> at connection.onclose (C:\Users\biket\Desktop\akikloforita\node_modules@discordjs\ws\dist\index.js:676:17)
> at callListener (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\event-target.js:290:14)
> at WebSocket.onClose
> (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\event-target.js:220:9)
> at WebSocket.emit (node:events:514:28)
> at WebSocket.emitClose (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\websocket.js:258:10)
> at TLSSocket.socketOnClose (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\websocket.js:1264:15)
> at TLSSocket.emit (node:events:526:35)
> at node:net:323:12
> at TCP.done (node:_tls_wrap:588:7)
>
> Node.js v18.17.0
这是我的代码:
const { Client, IntentsBitField } = require('discord.js');
const client = new Client({ intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent,
],
});
client.on('ready', (c) => {
console.log(`✅ ${c.user.tag} is online.`);
});
client.on('messageCreate', (message) => {
if (message.content === 'hello') {
message.reply('Hey!');
}
})
client.login("my_token")
有人可以帮我吗?
英文:
I make a discord bot and got this error
I try to add when a member send hello the bot reply hi
I do it form a tutorial in youtube for a server.
and i got this error:
> C:\Users\biket\Desktop\akikloforita\node_modules@discordjs\ws\dist\index.js:1132
> error: new Error("Used disallowed intents")
> ^
>
> Error: Used disallowed intents
> at WebSocketShard.onClose (C:\Users\biket\Desktop\akikloforita\node_modules@discordjs\ws\dist\index.js:1132:18)
> at connection.onclose (C:\Users\biket\Desktop\akikloforita\node_modules@discordjs\ws\dist\index.js:676:17)
> at callListener (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\event-target.js:290:14)
> at WebSocket.onClose
> (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\event-target.js:220:9)
> at WebSocket.emit (node:events:514:28)
> at WebSocket.emitClose (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\websocket.js:258:10)
> at TLSSocket.socketOnClose (C:\Users\biket\Desktop\akikloforita\node_modules\ws\lib\websocket.js:1264:15)
> at TLSSocket.emit (node:events:526:35)
> at node:net:323:12
> at TCP.done (node:_tls_wrap:588:7)
>
> Node.js v18.17.0
const { Client, IntentsBitField } = require('discord.js');
const client = new Client({ intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent,
],
});
client.on('ready', (c) => {
console.log(`✅ ${c.user.tag} is online.`);
});
client.on('messageCreate', (message) => {
if (message.content === 'hello') {
message.reply('Hey!');
}
})
client.login("my_token")
Can someone help me?
</details>
# 答案1
**得分**: 3
启用[Discord开发者门户](https://discord.com/developers/applications)中的`服务器成员`和`消息内容`特权意图。[![][1]][1]
[1]: https://i.stack.imgur.com/NM3aC.jpg
<details>
<summary>英文:</summary>
Enable `Guild Members` and `Message Content` Privileged Intents in [Discord Developer Portal](https://discord.com/developers/applications).
[![][1]][1]
[1]: https://i.stack.imgur.com/NM3aC.jpg
</details>
# 答案2
**得分**: 1
你需要在你的应用程序[这里](https://discord.com/developers/applications "Discord开发者门户")启用`Server Members`意图和`Message Content`意图。
<details>
<summary>英文:</summary>
You have to enable `Server Members` intent and `Message Content` intent on your Application [here](https://discord.com/developers/applications "Discord Developer Portal")
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论