generated at
Gateway Intents を指定するサンプル
事前に GatewayIntentBits クラスをrequireしておく。
main.js
const { Client, GatewayIntentBits: { Guilds, GuildMessages, MessageContent } } = require("discord.js"); // import { Client, GatewayIntentBits } from "discord.js"; // const { Guilds, GuildMessages, MessageContent } = GatewayIntentBits; const options = { intents: [Guilds, GuildMessages, MessageContent], }; const client = new Client(options);

v13と同じように、ビット論理和や文字列などでも指定できる。

Intent名の配列を指定することができる
GUILDS と GUILD_MESSAGES の2つのインテントを設定してクライアントを作成している
main.js
const options = { intents: ["GUILDS", "GUILD_MESSAGES"], }; const client = new Client(options);

Intentフラグの論理和でも指定できる
事前に Intents クラスをrequireしておく。
main.js
const { Intents, Client } = require("discord.js"); // import { Intents, Client } from "discord.js";
main.js
const options = { intents: Intents.FLAGS.GUILDS | Intents.FLAGS.GUILD_MESSAGES, }; const client = new Client(options);

事前に Intents クラスをrequireしておく。
main.js
const { Intents, Client } = require("discord.js"); // import { Intents, Client } from "discord.js";

v12ではwsの中にintentsとして指定する必要がある
すべてのIntentを使用するよう宣言する
main.js
const options = { ws: { intents: Intents.ALL, }, }; const client = new Client(options);

すべての特権でないIntentを仕様するよう宣言できる
main.js
const options = { ws: { intents: Intents.NON_PRIVILEGED, }, }; const client = new Client(options);
Intent名の配列を指定することができる
GUILDS と GUILD_MESSAGES の2つのインテントを設定してクライアントを作成している
main.js
const options = { ws: { intents: ["GUILDS", "GUILD_MESSAGES"], }, }; const client = new Client(options);

Intentフラグの論理和でも指定できる
main.js
const options = { ws: { intents: Intents.FLAGS.GUILDS | Intents.FLAGS.GUILD_MESSAGES, }, }; const client = new Client(options);

main.js
const options = { ws: { intents: Intents.ALL&~(Intents.FLAGS.GUILD_MESSAGE_TYPING|Intents.FLAGS.DIRECT_MESSAGE_TYPING), }, }; const client = new Client(options);

指定できる全ての値はIntentsResolvableに書いてある

v12とv13の両方で動かす
main.js
const intents = Intents.FLAGS.GUILDS | Intents.FLAGS.GUILD_MESSAGES; const options = { intents, ws: { intents, }, }; const client = new Client(options);