我尝试制作一个Discord机器人,但我遇到了这个错误。

huangapple go评论142阅读模式
英文:

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 &quot;Discord Developer Portal&quot;)

</details>



huangapple
  • 本文由 发表于 2023年8月11日 04:42:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76879191.html
  • discord
  • discord.js
  • node.js

在Nunjucks模板中访问数组在 :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定