3
2

More than 1 year has passed since last update.

discord.jsのバージョンを13から14に移行する

Posted at

一昨日バージョンを下げるのを試してみてくださいという記事を書きましたが運営してるbotのコードをv14用に変えたのでついでに記事を書きます。

Intentsがv13とは違う

今まではFLAGS.GUILD_MESSAGESのようなIntentsでしたがv14からはGatewayIntentBits.MessageContentのようなIntentsになります。
なので一昨日の記事のようなエラーが出るのです。
APIの変更により2022/8/31よりメッセージ内容読み取りのIntentsが必要になります。

Discord Developersよりbotを選択
Bot→MESSAGE CONTENT INTENTをONにする
IMG_20220721_144524.jpg
IMG_20220721_144556.jpg

もちろんコード側のIntentsの変更も必要になります。

index.js
const { Client, GatewayIntentBits, Partials } = require("discord.js")
const client = new Client({
  'intents': [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ],
  'partials': [Partials.Channel]
});

自分はこのようにしました。
記事見ていただきありがとうございました

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2