admin管理员组文章数量:1426122
Do you know why the "message sent" is displayed only with the first solution?
const Discord = require("discord.js");
const config = require("./config.json");
const intents = new Discord.Intents(32767);
const client = new Discord.Client({ intents });
client.on("ready", () => {
console.log("bot is ready");
});
client.on("messageCreate", (message) => {
console.log("message sent");
});
client.login(config.token);
And not with this? (That is the example code on the discord.js documentation.)
const config = require("./config.json");
const { Client, Intents } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.on("ready", () => {
console.log("bot is ready");
});
client.on("messageCreate", (message) => {
console.log("message sent");
});
client.login(config.token);
The bot is ready in both solutions, but I don't get why only in the first one when I send a message in the server the bot detects it, maybe because I don't know what does mean "32767".
Do you know why the "message sent" is displayed only with the first solution?
const Discord = require("discord.js");
const config = require("./config.json");
const intents = new Discord.Intents(32767);
const client = new Discord.Client({ intents });
client.on("ready", () => {
console.log("bot is ready");
});
client.on("messageCreate", (message) => {
console.log("message sent");
});
client.login(config.token);
And not with this? (That is the example code on the discord.js documentation.)
const config = require("./config.json");
const { Client, Intents } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.on("ready", () => {
console.log("bot is ready");
});
client.on("messageCreate", (message) => {
console.log("message sent");
});
client.login(config.token);
The bot is ready in both solutions, but I don't get why only in the first one when I send a message in the server the bot detects it, maybe because I don't know what does mean "32767".
Share Improve this question edited Aug 17, 2021 at 22:25 Skulaurun Mrusal 2,8451 gold badge17 silver badges30 bronze badges asked Aug 17, 2021 at 15:48 user14728703user147287031 Answer
Reset to default 1The number 32767
means ALL_INTENTS
. The Intents
class extends a BitField
. Meaning that you can represent all the intents you want via a single number by filling in specific bits of the bitfield.
According to Discord Developer Portal, this is how each flag is represented by a bit shift.
const ALL_INTENTS =
(1 << 0) + // GUILDS
(1 << 1) + // GUILD_MEMBERS
(1 << 2) + // GUILD_BANS
(1 << 3) + // GUILD_EMOJIS_AND_STICKERS
(1 << 4) + // GUILD_INTEGRATIONS
(1 << 5) + // GUILD_WEBHOOKS
(1 << 6) + // GUILD_INVITES
(1 << 7) + // GUILD_VOICE_STATES
(1 << 8) + // GUILD_PRESENCES
(1 << 9) + // GUILD_MESSAGES
(1 << 10) + // GUILD_MESSAGE_REACTIONS
(1 << 11) + // GUILD_MESSAGE_TYPING
(1 << 12) + // DIRECT_MESSAGES
(1 << 13) + // DIRECT_MESSAGE_REACTIONS
(1 << 14); // DIRECT_MESSAGE_TYPING
// Outputs 32767
console.log(ALL_INTENTS);
Do you know why the "message sent" is displayed only with the first solution?
Because in the second solution, you are missing GUILD_MESSAGES
intent to receive the messageCreate
event.
本文标签: javascriptDiscordIntents(32767) vs IntentsFLAGSGUILDSStack Overflow
版权声明:本文标题:javascript - Discord.Intents(32767) vs [Intents.FLAGS.GUILDS]? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745378222a2656036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论