generated at
v13の主な変更箇所
Node.js のv16.6を前提として書かれるようになる。
Webpackビルドはサポートされない。
API v9に接続する。

音声関連
discord.js本体からdiscordjs/voiceへ分割された
refactor: remove all voice code discordjs/discord.js#5818

よく使われるメソッドやオプションについて
Client
new Client(options)
v12では options は空でよかったがv13ではGateway Intentsの指定が必要になった
message イベントが非推奨に
messageCreate イベントを代わりに使用する
diff
- client.on("message", message => { /*do stuff*/ }) + client.on("messageCreate", message => { /*do stuff*/ })
現時点では一回だけ警告が出力される
また、DMでのメッセージの受信には CHANNEL partialの指定が必要になった
タイマー関連のメソッド( Client#setTimeout , Client#setInterval など)が削除
application
diff
- const application = await client.fetchApplication(); + const application = client.application; + // const application = await client.application.fetch();

ClientOptions
ClientOptions#disableMentions
ClientOptions#allowedMentions に置き換えられた
ClientOptions#fetchAllMembers
廃止
ClientOptions#messageEditHistoryMaxSize
編集履歴の保存を行う機能は廃止

***ID
***Id に置き換えられた。
diff
- console.log(guild.ownerID); + console.log(guild.ownerId); - console.log(message.webhookID); + console.log(message.webhookId);

send / edit
1引数しか取らなくなった。
diff
- channel.send('content', { embed: new MessageEmbed().setDescription("desc") }); + channel.send({ content: 'content', embeds: [ new MessageEmbed().setDescription("desc") ]});
string は依然としてそのまま送れる
js
channel.send('hello!');
MessageEmbed / MessageAttachment のインスタンスもしくはその配列を直接取らなくなった。
diff
- channel.send(new MessageEmbed().setDescription("desc")); + channel.send({ embeds: [ new MessageEmbed().setDescription("desc") ] });
MessageOptions#embed
MessageOptions#embeds に置き換えられた。
Discord APIが通常のメッセージの送信においても複数のembedを送信することに対応したため。
diff
- channel.send({ embed: { description: "desc" } }); + channel.send({ embeds: [ { description: "desc" } ] });
MessageOptions#code および、 MessageOptions#split は削除
今後は、 Foramtters.codeBlock および、 Util.split を使用する

StringResolvable
StringResolvable はなくなり、今まで StringResolvable を受け取っていたものは単なる string のみを受け取るようになる。
diff
- new MessageEmbed().setDescription(new Date()); + new MessageEmbed().setDescription(String(new Date())); - new MessageEmbed().setDescription(guild.description);//nullの場合にnullという文字列が送信されていた // エラーになるため適当な代替テキストを用意する + new MessageEmbed().setDescription(guild.description ?? "altanative text"); // 存在する場合のみ設定する + const embed = new MessageEmbed(); + if(guild.description != null) embed.setDescription(guild.description);
feat(*): enforce strings#4880 discordjs/discord.js

MessageEmbed#attachFiles MessageEmbed#files
削除
diff
- const embed = new Discord.MessageEmbed().setTitle('Attachments').attachFiles(['./image1.png', './image2.jpg']); - channel.send(embed); + const embed = new Discord.MessageEmbed().setTitle('Attachments'); + channel.send({ embeds: [embed], files: ['./image1.png', './image2.jpg'] });

Reply関連
Message#reply
いままでこれはメッセージを作成したユーザーへのメンションを含むメッセージを作成する振る舞いをしていたが、Discordの返信機能を使用するようになる。
MessageOptions#reply
diff
- channel.send('content', { reply: '123456789012345678' }); // User ID + channel.send({ content: 'content', reply: { messageReference: '765432109876543219' }}); // Message ID or MessageResolvable
MessageOptions#allowedMentions.repliedUser
MessageOptions#allowedMentions.repliedUser オプションにより、Reply先のメッセージの作成者にメンションをするか指定できる。
diff
- message.reply('content'); + message.reply({ content: 'content', allowedMentions: { repliedUser: false }});

Chennel#type
Discord APIの名前と同じ名前に変更された。
diff
// news channel - channel.type === 'news' + channel.type === 'GUILD_NEWS' // text channel - channel.type === 'text' + channel.type === 'GUILD_TEXT' // direct mail - channel.type === 'dm' + channel.type === 'DM' // voice channel - channel.type === 'voice' + channel.type === 'GUILD_VOICE'

Intents
ALL PRIVILEGED NON_PRIVILEGED は削除
使う Intents を個別に列挙しなければならない
Object.values(Intents.FLAGS) とすることで、 ALL を再現できる

typing 関連
Channel#startTyping stopTyping 等は削除
sendTyping が追加されたがこれは一度だけAPIに typing を送るもので、 startTyping を直接置き換えるものではない。
この変更で140MB/100万チャンネルだけ軽くなったらしい

Guild
Guild#member()
直接cacheから取得するよう改められた。
diff
- guild.member(user); + guild.members.cache.get(user.id); + // guild.members.resolve(user);
Guild#voice
meを経由するよう改められた
diff
- guild.voice + guild.me.voice
Guild#owner
Guild#fetchOwner() で置き換えられる
あるいは ownerId を用いることもできる
diff
- guild.owner; + await guild.fetchOwner(); + guild.fetchOwner().then(owner => { /* do stuff */ });
diff
- guild.owner.id - guild.ownerID + guild.ownerId
Guild#fetchInvites()
Guild#invites fetch メソッドになる
これに伴い GuildInviteManager というものが追加された
Guild#fetchBans()
Guild#bans fetch メソッドになる
Guild#bans にはキャッシュもあるが、fetchしないと空のコレクションが返ってきたsuzuneu

GuildMember
GuildMember#hasPermission
削除

DMChannel
DM でのメッセージを受け取るためには CHANNEL partialが必ず必要になる。
discord apiはv8以降では、 DM について channelCreate イベントを送信しない。
そのためキャッシュが作られない

Message / MessageManager
Message#delete
timeout オプションは削除される
代わりにグローバルな setTimeout() を使う
diff
- const m = await message.channel.send("5秒後に削除されます"); - m.delete({ timeout: 5000 }); + const m = await message.channel.send("5秒後に削除されます"); + setTimeout(() => m.delete(), 5000);

Collector/awaitXXX 関連
1つの引数を取るように変更された。
diff
- const collector = message.createReactionCollector(filter, { time: 15000 }); + const collector = message.createReactionCollector({ filter, time: 15000 }); - message.channel.awaitMessages(msg => !msg.author.bot, { max: 1, time: 15000}); + message.channel.awaitMessages({ filter: msg => !msg.author.bot, max: 1, time: 15000})
max で指定した条件を達成できなかった場合、エラーを出力するようにもできるようになった?
Message#awaitReactions() は例外みたいsuzuneu
この記述自体違くない?tig
diff
- message.channel.awaitMessages(msg => !msg.author.bot, { max: 1, time: 15000}) - .then(collected => { - if (!collected.size) return message.reply("何も送信されませんでした"); - message.reply("あなたは" + collected.first().content + "を送信しました"); - }); + message.channel.awaitMessages({ filter: msg => !msg.author.bot, max: 1, time: 15000}) + .then(collected => { + message.reply("あなたは" + collected.first().content + "を送信しました"); + }) + .catch(collected => { + message.reply("何も送信されませんでした"); + });

User
User#locale
OAuth2を使用してユーザーの認可を得ない限り locale の取得は不可能になった。
そのため、このフィールドは削除される。
User#presence
廃止
代わりに以前もあった GuildMember#presence を使用することになる

Snowflake
SnowflakeUtil を使用する。
エクスポートされなくなる
これまでもドキュメント上では存在しなかったものの実際には利用できた
ts/jsdocユーザーへ
型としての Snowflake はエクスポートされています。
型が string から Snowflake へ変更されている部分がかなりあります。
実行時の型としては string のままですが、コンパイル時にはTemplate Literal Typesを使用して定義された Snowflake 型を使用しています。

Structures
削除
フレームワークに対してはインパクトの大きい変更
なんか消さないように揉めてたけどまぁ筋の悪い機能だったし仕方ないtig

Activity
Activity#type
CUSTOM_STATUS CUSTOM に変更された

major ではないけど言及する価値があると思われるもの
Instance#fetch 系のメソッドがデフォルトでDiscord APIへリクエストを行うようになる
対象は Channel DMChannel GuildBan GuildMember User Message でマネージャーは対象とはなっていない
こういうものを minor で出すのは正直どうかと思うtig

コードの変更ではないもの

discord.js自体ではないもの
Collection
Collection#array()
廃止
Collection#toJSON()
廃止