v14の主な変更箇所
API v10に接続する。
ビルダーが内包されるようになった。
名前の競合を避けるために @discordjs/builders
をアンインストールすることをおすすめする。
Enums
要素の命名規則が、SCREAMING_SNAKE_CASE から PascalCase へと変更された。
今まで列挙型(enum)の数値と文字列を受け入れていたパラメーターは、基本的に数値のみを受け入れるようになった。ただし、BitFieldResolvable (IntentsやPermissionsなど) は、文字列も受け入れる。
例:
diff- new Client({ intents: ["GUILDS"], partials: ["CHANNEL"] });
+ new Client({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] });
diff+ const { ApplicationCommandType } = require('discord.js');
client.application.commands.create({
name: "ping",
- type: "CHAT_INPUT",
+ type: ApplicationCommandType.ChatInput
});
diff- const { MessageButton } = require("discord.js");
+ const { ButtonBuilder, ButtonStyle } = require("discord.js");
- const button = new MessageButton()
+ const button = new ButtonBuilder()
.setCustomId("sample")
- .setStyle("PRIMARY")
+ .setStyle(ButtonStyle.Primary)
.setLabel("Sample Button")
BitFields
GatewayIntentBits
v13で使われていたIntentsの代わりになるもの。注意してほしいのは
v13
では
Intents.FLAGS(.~~~)
となっていたが、
v14では
GatewayIntentBits(.~~~)
となる。また、
2022年8月31日のDiscord APIの仕様変更の影響だからなのか、
MessageContent
のIntentsが追加された。このIntentsがないとメッセージの内容がわからなくなる。
v13ではIntentsを指定する場合、すべて大文字(例:
Intents.FLAGS.GUILDS
)だったが、
v14ではそれが変更された。(例:
GatewayIntentBits.Guilds
)
以下のものは名前が変わっただけだと思われるもの、ただし .FLAGS
が .Flags
になるなどの変更があったりする。
IntentsBitField (Intentsから変更)
MessageContent Intent が追加された。
IntentsBitField.Flags
は GatewayIntentBits
と全く同じになる。
PermissionsBitField (Permissionsから変更)
Discord API で USE_PUBLIC_THREADS
と USE_PRIVATE_THREADS
が非推奨とされ、 CREATE_PUBLIC_THREADS
と CREATE_PRIVATE_THREADS
が追加されたため、それに対応して変更が行われた。
MessageFlagsBitField (MessageFlagsから変更)
UserFlagsBitField (UserFlagsから変更)
ThreadMemberFlagsBitField (ThreadMemberFlagsから変更)
ApplicationFlagsBitField (ApplicationFlagsから変更)
ActivityFlagsBitField (ActivityFlagsから変更)
SystemChannelFlagsBitField (SystemChannelFlagsから変更)
Channels
isText()
、 isVoice()
、 isDM()
、 isDirectory()
、 isGroupDM()
、 isCategory()
、 isNews()
メソッドが削除
チャンネルの識別は channel.type
で行う。
jsconst { ChannelType } = require("discord.js")
if (channel.type === ChannelType.GuildText){
//...
}
Interactions
Interaction#isAutoComplete()、Interaction#isApplicationCommand()、Interaction#isMessageComponent()、Interaction#isModalSubmit()は廃止。interaction.type を使って識別する。
メソッド名の変更
Interaction#isCommand()
は BaseInteraction#isChatInputCommand()
Interaction#isContextMenu()
は BaseInteraction#isContextMenuCommand()
Interaction#isMessageContextMenu()
は BaseInteraction#isMessageContextMenuCommand()
Interaction#isUserContextMenu()
は BaseInteraction#isUserContextMenuCommand()
クラス名の変更
Interaction
→ BaseInteraction
BaseCommandInteraction
→ CommandInteraction
CommandInteraction
→ ChatInputCommandInteraction
ContextMenuInteraction
→ ContextMenuCommandInteraction
UserContextMenuInteraction
→ UserContextMenuCommandInteraction
MessageContextMenuInteraction
→ MessageContextMenuCommandInteraction
Builders
EmbedBuilder
MessageEmbed
がこれに変わった。変更点は .addField()
が消えたこと。
→ .addFields()
を使うが、v13のように引数は配列にするのではなく、複数の引数を並べる形になる。(v13でも複数の引数を並べる形でつかうことはできた)
ButtonBuilder
(MessageButton から変更)
SelectMenuBuilder
MessageSelectMenu
がこれに変わった。 EmbedBuilder
と同じように、 .addOption()
が削除された。
ActionRowBuilder
(MessageActionRow から変更)
TextInputBuilder
(TextInputComponent から変更)
ModalBuilder
(Modal から変更)
AttachmentBuilder
( MessageAttachment から変更)
discord.js
から引っぱってきてうまく動かない場合は @discordjs/builders
から取ってくるのも1つの手段
REST
client.on("apiRequest", () => {})
は client.rest.on("request", () => {})
に変更。
client.on("apiResponse", () => {})
は client.rest.on("response", () => {})
に変更。
client.on("rateLimit", () => {})
は client.rest.on("rateLimited", () => {})
に変更。
client.on("invalidRequestWarning", () => {})
は削除された。
apiを直接叩くときに使われていた client.api. ... .{httpMethod}(args)
系は、削除された。これからは client.rest.{httpMethod}(args)
系を使う必要がある。
diff- client.api.channels[channelId].messages[messageId].get()
+ client.rest.get(`channels/${channelId}/messages/${messageId}/`)
create() と edit() の引数の統合
Guild#edit()
GuildChannel#edit()
GuildEmoji#edit()
Role#edit()
Sticker#edit()
ThreadChannel#edit()
GuildChannelManager#edit()
GuildEmojiManager#edit()
GuildMemberManager#edit()
GuildMember#edit()
GuildStickerManager#edit()
RoleManager#edit()
Webhook#edit()
これらは第一引数に reason の入ったオブジェクトを取るようになる。
diffrole.edit(
- { name: "新しいロールの名前" },
+ { name: "新しいロールの名前", reason: "理由" }
- "理由"
)
⚠️ Xxxx#create メソッドの記述もれ
Activity クラス
id
, platform
, sessionId
, syncId
プロパティーが削除された。
Application クラス
Application#fetchAssets
メソッドが削除された。
CategoryChannel クラス
これに伴い CategoryChannel#createChannel()
メソッドも消えて CategoryChannelChildManager#create
に移動した。
ImageURLOptions
format
オプションが削除され、代わりに extension
オプションが追加された。
dynamic
オプションが削除され、反対の働きをする forceStatic
オプションが追加された。
PartialTypes → Partial
ThreadMember
が追加された。
要素の命名規則が、SCREAMING_SNAKE_CASE から PascalCase へと変更された。
Util → (deleted)
Util.removeMentions()
, Util.splitMessage()
, Util.resolveAutoArchiveMaxLimit()
メソッドが削除された。
それ以外のメソッドはトップレベルへ移動された。以下はその例。
diff- import { Util } from 'discord.js';
- const { Util } = require('discord.js');
- Util.escapeMarkdown()
+ import { escapeMarkdown } from 'discord.js';
+ const { escapeMarkdown } = require('discord.js');
+ escapeMarkdown()
GuildBanManager クラス
GuildBanManager#days
プロパティーは deleteMessageDays
に名前が変更された。
Guild クラス
Guild#setRolePositions()
と Guild#setChannelPositions()
が削除された。代わりに、 RoleManager#setPositions()
と GuildChannelManager#setPositions()
を使用する必要がある。
GuildAuditLogs クラス & GuildAuditLogsEntry クラス
GuildAuditLogs.build()
が削除された。
以下のプロパティーとメソッドが GuildAuditLogsEntry
クラスに移動された。
GuildAuditLogs.Targets
GuildAuditLogs.actionType()
GuildAuditLogs.targetType()
GuildMember クラス
GuildMember#pending
プロパティーが nullable になった。
IntegrationApplication クラス
IntegrationApplication#summary
プロパティーが削除された。
Invite クラス
Invite#channel
と Invite#inviter
が Getter になった。
MessageManager クラス
MessageManager#fetch()
メソッドの引数が1つだけになった。
Role クラス, RoleManager クラス
Role.comparePositions()
メソッドが削除された。代わりに RoleManager#comparePositions()
メソッドを使用する必要がある。
Sticker クラス
Sticker#tags
プロパティーの型が string[] | null
から string | null
に変更された。
ThreadChannel クラス
ThreadAutoArchiveDuration
type から MAX
が削除された。
ThreadMemberManager クラス
ThreadMemberManager#fetch()
メソッドの引数が1つだけになった。
deleted プロパティーの削除
色々なクラスの deleted
プロパティーが削除された。
VoiceChannel クラス
VoiceChannel#editable
プロパティーが削除され、代わりに VoiceChannel#manageable
プロパティーが追加された。
VoiceRegion クラス
VoiceRegion#vip
プロパティーが削除された。
Webhook クラス
Webhook#fetchMessage()
メソッドの引数が1つだけになった。
イベント
Client
の applicationCommandCreate
, applicationCommandDelete
, applicationCommandUpdate
イベントが削除された。
⚠️ The threadMembersUpdate event now emits the users who were added, the users who were removed, and the thread respectively.
PermissionOverwritesManager クラス
permission が、SCREAMING_SNAKE_CASE から PascalCase へと変更された。