# v11からv12へのアップデート
長期間の開発の末、Discord.js v12は正式にリリースされました。つまり、v11から更新してボットで新しい機能を使うときです!しかし追加された新機能と同時に、v11向けに書かれたコードを壊すライブラリへの多くの変更があります。このガイドは、コードを更新するための便利なリファレンスとして機能し、変更された最もよく使用されるメソッドや、パーシャル、内部シャーディングなどの新しいトピックをカバーします。最後にメソッドとプロパティの変更の包括的なリストも含まれます。
TIP
このガイドには2つのバージョンがあります! ガイド全体で新バージョンのコードスニペットと説明を得るために、ヘッダーのドロップダウンでv12 (stable)
を選択することを確認してください。
# 始める前に
v12を使用するにはNode 12.x以降が必要です。最新の状態であることを確認してください。Nodeのバージョンを確認するには、ターミナルまたはコマンドプロンプトでnode -v
を使用します。v12以降ではない場合は更新してください。使用しているOSごとにこれを手助けする情報がネット上に多くあります。
Nodeを最新にしたら、ターミナルまたはコマンドプロンプトでnpm install discord.js
を実行してテキストのみを使用するか、音声サポート用にnpm install discord.js @discordjs/opus
を実行してv12をインストールできます。
インストールされたdiscord.jsのバージョンはnpm list discord.js
で確認できます。それでもv11.xが表示される場合はdiscord.jsを一度アンインストールし(npm uninstall discord.js
)、再びインストールすることで、package.jsonの指定がメジャーバージョンの更新を妨げていないことを確認してください。詳しくはnpm documentationを参照してください。
# 変更されたよく使われるメソッド
- すべての節の見出しには、
Class#methodOrProperty
という規則に従って名前が付けられます。 - 括弧の使用は、オプションを含むことを表します。例えば
Channel#fetch(Pinned)Message(s)
は、その節にChannel#fetchPinnedMessages
、Channel#fetchMessages
、およびChannel#fetchMessage
の変更が含まれることを意味します。 - アスタリスクはワイルドカードを示します。例えば
Channel#send***
は、このセクションにChannel#sendMessage
やChannel#sendFile
、Channel#sendEmbed
などの変更が含まれることを意味します。
# マネージャー/ キャッシュ
v12ではマネージャーという概念が導入されているため、Client#users
などのデータ構造でCollection#get
などのコレクションメソッドを直接使用することはできなくなります。コレクションのメソッドを使用する前に、マネージャーでキャッシュを直接要求する必要があります。GuildMemberManager#fetch
やMessageManager#delete
など、マネージャーで直接呼び出されるメソッドはAPIを呼び出します。
- client.users.get('123456789012345678');
+ client.users.cache.get('123456789012345678');
- channel.messages.get('123456789012345678');
+ channel.messages.cache.get('123456789012345678');
- guild.members.get('123456789012345678');
+ guild.members.cache.get('123456789012345678');
# Collection
# Collection#exists
collection.exists()
は完全に削除されました。collection.some()
を使用して、指定された値を満たす要素がコレクション内に存在するかどうかを確認する必要があります。
- client.users.exists('username', 'Bob');
+ client.users.cache.some(user => user.username === 'Bob');
# Collection#filterArray
collection.filterArray()
は完全に削除されました。これは単なるcollection.filter().array()
のヘルパーメソッドであり、ほとんどの場合、コレクションを配列に変換することは不要な操作です。
# Collection#find
collection.find('property', value)
は完全に削除されました。v12のcollection.find()
では関数のみを受け入れます。
- client.users.find('username', 'Bob');
+ client.users.cache.find(user => user.username === 'Bob');
# Collection#findAll
collection.findAll()
は、collection.filterArray()
の結果を複製するだけなので、完全に削除されました。
# Fetch
キャッシュされていないデータを取得する一部のメソッドが変更され、マネージャーを使用する形式に変更されました。
- client.fetchUser('123456789012345678');
+ client.users.fetch('123456789012345678');
- guild.fetchMember('123456789012345678');
+ guild.members.fetch('123456789012345678');
- guild.fetchMembers();
+ guild.members.fetch();
- textChannel.fetchMessage('123456789012345678');
+ textChannel.messages.fetch('123456789012345678');
- textChannel.fetchMessages({ limit: 10 });
+ textChannel.messages.fetch({ limit: 10 });
- textChannel.fetchPinnedMessages();
+ textChannel.messages.fetchPinned();
# Send
すべての.send***()
メソッドは削除され、1つの一般的な.send()
メソッドが採用されました。
- channel.sendMessage('Hey!');
+ channel.send('Hey!');
- channel.sendEmbed(embedVariable);
+ channel.send(embedVariable);
+ channel.send({ embed: embedVariable });
channel.send(embedVariable)
は、その変数が MessageEmbed
クラスのインスタンスである場合にのみ機能します。埋め込みデータがembed
キー内にない限り、オブジェクトリテラルは期待した結果になりません。
- channel.sendCode('js', 'const version = 11;');
+ channel.send('const version = 12;', { code: 'js' });
- channel.sendFile('./file.png');
- channel.sendFiles(['./file-one.png', './file-two.png']);
+ channel.send({
+ files: [{
+ attachment: 'entire/path/to/file.jpg',
+ name: 'file.jpg'
+ }]
+ });
+ channel.send({
+ files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
+ });
# 役職
GuildMember.roles
コレクションはv12でマネージャーに変更されたため、メンバーの役職とやり取りするための多くの関連メソッドも変更されました。それらはもはやGuildMemberオブジェクトではなく、GuildMemberRoleManager
です。マネージャーは役職のAPIメソッドとキャッシュを、プレーンなコレクションであるGuildMemberRoleManager#cache
の形式で保持します。
- guildMember.addRole('123456789012345678');
- guildMember.addRoles(['123456789012345678', '098765432109876543']);
+ guildMember.roles.add('123456789012345678');
+ guildMember.roles.add(['123456789012345678', '098765432109876543']);
- guildMember.removeRole('123456789012345678');
- guildMember.removeRoles(['123456789012345678', '098765432109876543']);
+ guildMember.roles.remove('123456789012345678');
+ guildMember.roles.remove(['123456789012345678', '098765432109876543']);
- guildMember.setRoles(['123456789012345678', '098765432109876543']);
+ guildMember.roles.set(['123456789012345678', '098765432109876543']);
- guildMember.roles.get('123456789012345678');
+ guildMember.roles.cache.get('123456789012345678');
さらに、役職に関連するGuildMemberプロパティもGuildMemberRoleManager
に移動されました。
- guildMember.colorRole;
+ guildMember.roles.color;
- guildMember.highestRole;
+ guildMember.roles.highest;
- guildMember.hoistRole;
+ guildMember.roles.hoist;
# BANとBAN解除
メンバーとユーザーをBANするメソッドは、GuildMemberManager
に移動しました。
- guild.ban('123456789012345678');
+ guild.members.ban('123456789012345678');
- guild.unban('123456789012345678');
+ guild.members.unban('123456789012345678');
# 画像URL
user.avatarURL
のような画像関連のプロパティはv12でメソッドになったため、それらに表示サイズを変えるなどのオプションを適用できます。
- user.avatarURL;
+ user.avatarURL();
- user.displayAvatarURL;
+ user.displayAvatarURL();
- guild.iconURL;
+ guild.iconURL();
- guild.splashURL;
+ guild.splashURL();
# 動的ファイルタイプ
バージョン12では、画像のファイルタイプを動的に設定できるようになりました。dynamic
オプションが提供されている場合、画像がアニメーション化されているときは.gif
のURLを受け取ります。それ以外の場合は、指定されたformat
またはデフォルトの.webp
にフォールバックします。
user.avatarURL({ format: 'png', dynamic: true, size: 1024 });
# RichEmbedコンストラクター
RichEmbedコンストラクターが削除され、MessageEmbed
コンストラクターが使用されるようになりました。使用方法はほとんど同じですが、違いはrichEmbed.attachFile
とrichEmbed.addBlankField
が削除され、代わりにmessageEmbed.addFields
が追加されました。(messageEmbed.attachFiles
はパラメーターとして単一のファイルも受け入れます)
# String Concatenation
v12 has changed how string concatenation works with stringifying objects. ThevalueOf
any data structure will return its id, which affects how it behaves in strings, eg. using an object for a mention. In v11, you used to be able to use channel.send(userObject + ' has joined!')
and it would automatically stringify the object and it would become the mention (@user has joined!
), but in v12, it will now send a message that says 123456789012345678 has joined
instead. Using template literals (``) will still return the mention, however.
v12では、文字列連結がオブジェクトを文字列化する方法が変更されました。データ構造体のvalueOf
はそのidを返します。これは、メンションにオブジェクトを使用するときなどの、文字列内での振る舞いに影響します。v11では、channel.send(userObject + ' has joined!')
を使用して、オブジェクトを自動的に文字列化しメンションにできましたが(@user has joined!
)、v12では123456789012345678 has joined
というメッセージを送信します。代わりにテンプレートリテラル(``)を使用するとメンションが返されます。
- channel.send(userObject + ' has joined!')
+ channel.send(`${userObject} has joined!`)
# ユーザーアカウント限定のメソッド
APIから一般公開されないため、すべてのユーザーアカウント限定のメソッドは削除されました。
# 音声
v12には安定性を向上させる新しい音声システムがありますが、オーディオの再生にいくつかの変更が加えられています。
# VoiceConnectionおよびVoiceBroadcastに適用
- connection.playFile('file.mp3')
+ connection.play('file.mp3')
- connection.playStream(stream)
+ connection.play(stream)
- connection.playArbitraryInput(input)
+ connection.play(input)
- connection.playBroadcast(broadcast)
+ connection.play(broadcast)
- connection.playOpusStream(stream)
+ connection.play(stream, { type: 'opus' })
- connection.playConvertedStream(stream)
+ connection.play(stream, { type: 'converted' })
また、v12でFFmpegを必要とせずに、Ogg OpusファイルまたはWebM Opusファイルを直接再生できるようになりました。
- connection.play(fs.createReadStream('file.ogg'), { type: 'ogg/opus' });
+ connection.play(fs.createReadStream('file.webm'), { type: 'webm/opus' });
ストリームを再生するときに、plp
、fec
、bitrate
の初期値を定義することもできます。マイナスビットレートは、不安定なネットワーク接続でオーディオを再生するときに役立つv12の新しい設定可能なオプションです。
- connection.playStream(stream).setBitrate(96)
+ connection.play(stream, { bitrate: 96 })
再生中にストリームの音量を変更する必要がない場合は、ボリュームを無効にしてパフォーマンスを改善できます。これは、再生中に元に戻すことはできません。
connection.play(stream, { volume: false });
v12の内部音声システムは、可能な限りストリームを使用するようになり、StreamDispatcher自体がWritableStreamになりました。また、新しい変更も含まれています。
- dispatcher.end()
+ dispatcher.destroy()
- dispatcher.on('end', handler)
+ dispatcher.on('finish', handler)
highWaterMark
オプション(デフォルトは12)を使用して、より安定した再生のためにオーディオを再生する前にキューに入れるオーディオパケットの数を手動で制御できます。
connection.play(stream, { highWaterMark: 512 });
オーディオストリームを頻繁に一時停止/再開する場合は、一時停止中に無音パケットの再生を有効にして、Discordクライアントでのノイズ(オーディオグリッチ)を防ぐことができます。
// trueを渡して”無音”を再生する
dispatcher.pause(true);
# ブロードキャスト
ブロードキャスト自体に、StreamDispatcher
と同じのインターフェースを共有し、オーディオストリームの再生を制御するために使用できるBroadcastDispatcher
が含まれるようになりました。
- client.createVoiceBroadcast()
+ client.voice.createBroadcast()
- broadcast.dispatchers
+ broadcast.subscribers
# 破壊的変更と削除
破壊的な変更の節の見出しは、v11のクラス/メソッド/プロパティにちなんで名前が付けられ、アルファベット順になっているため、探しているものを簡単に見つけることができます。追加の節ヘッダーには、現在の構文を適切に反映するために、v12クラス/メソッド/プロパティにちなんで名前が付けられます。
「差分」コードブロックは、古いメソッドと新しいメソッドを表示するために使用されます。赤は削除されたもので、緑はその代替です。一部には、処理されるバージョンが複数ある場合があります。反対に追加は、通常のJavaScript構文コードブロックが使用されます。
このリストは慎重に作成されていますが、不完全な場合があります!データの欠落や不正確な部分に気付いた場合は、[プルリクエストを送信する](https://github.com/discordjs/guide/compare)ことをお勧めします!
- Activity (additions)
- ActivityFlags (additions)
- APIMessage (additions)
- Base (additions)
- BaseClient (additions)
- BitField (additions)
- BroadcastDispatcher (additions)
- Channel (changed send/fetch to TextChannel) (additions)
- ClientApplication (additions)
- Client (changes) (additions)
- ClientOptions (changes) (additions)
- ClientUser (changes)
- Collection (changes)
- Collector (changes) (additions)
- CollectorOptions (additions)
- DMChannel (changes) (additions)
- Emoji (changes)
- EvaluatedPermissions (changes)
- Game (changes)
- GroupDMChannel (changes)
- Guild (changes) (additions)
- GuildChannel (changes) (additions)
- GuildMember (changes)
- HTTPError (additions)
- Invite (changes)
- Message (changes) (additions)
- MessageAttachment (changes) (additions)
- MessageCollectorOptions (changes)
- MessageEmbed (changes) (additions)
- MessageMentions (changes)
- MessageReaction (changes)
- OAuth2Application (changes)
- PartialGuild (changes)
- PartialGuildChannel (changes)
- Permissions (changes) (additions)
- Presence (changes) (additions)
- ReactionCollector (additions)
- ReactionEmoji (changes)
- RichEmbed (changes)
- RichPresenceAssets (changes)
- Role (changes)
- Shard (changes)
- ShardClientUtil (changes)
- ShardingManager (changes)
- StreamDispatcher (changes)
- TextChannel (changes) (additions)
- User (changes) (additions)
- Util (changes)
- VoiceBroadcast (changes) (additions)
- VoiceChannel (additions)
- VoiceConnection (changes)
- VoiceReceiver (changes) (additions)
- VoiceRegion (changes)
- VoiceState (additions)
- VolumeInterface (changes)
- Webhook (changes) (additions)
- WebhookClient (changes)
- WebSocketManager (additions)
- WebsocketOptions (additions)
- WebSocketShard (additions)
# 依存関係
# Snekfetch
Please note that snekfetch
has been removed as a dependency, and has been replaced by node-fetch
. snekfetch
has been deprecated by its developer and is no longer maintained.
# Attachment
The Attachment
class has been removed in favor of the MessageAttachment
class.
# Client
# Client#fetchUser
client.fetchUser()
has been removed and transformed in the shape of a Manager.
- client.fetchUser('123456789012345678');
+ client.users.fetch('123456789012345678');
# Client#broadcasts
client.broadcasts
has been removed and is now in the ClientVoiceManager
class.
- client.broadcasts;
+ client.voice.broadcasts;
# Client#browser
client.browser
has been changed to be an internal constant and is no longer available publicly.
# Client#channels
client.channels
has been changed from a Collection to a Manager.
# Client#clientUserGuildSettingsUpdate
The client.clientUserGuildSettingsUpdate
event has been removed entirely, along with all other user account-only properties and methods.
# Client#clientUserSettingsUpdate
The client.clientUserSettingsUpdate
event has been removed entirely, along with all other user account-only properties and methods.
# Client#destroy
The client.destroy()
method no longer returns a Promise.
# Client#disconnect
The client.disconnect
event has been removed in favor of the client.shardDisconnect
event to make use of internal sharding.
- client.on('disconnect', event => {});
+ client.on('shardDisconnect', (event, shardID) => {});
# Client#emojis
client.emojis
has been changed from a Collection to a Manager.
# Client#guildMemberSpeaking
The speaking
parameter has been changed from a boolean
value to a read-only Speaking
class.
# Client#guilds
client.guilds
has been changed from a Collection to a Manager.
# Client#ping
client.ping
has been moved to the WebSocketManager under client.ws.ping
- client.ping
+ client.ws.ping
# Client#pings
client.pings
has been moved to the WebSocketShard
class to make use of internal sharding. The Client
class has a Collection
of WebSocketShard
s available via client.ws.shards
; alternatively, the WebSocketShard
can be found as a property of other structures, eg guild.shard
.
- client.pings;
+ guild.shard.ping;
# Client#presences
client.presences
has been removed to reduce extraneous getters.
# Client#presenceUpdate
The client.presenceUpdate
has been changed and now passes the old and new Presence
rather than the GuildMember
.
- client.on('presenceUpdate', (oldMember, newMember) =>
+ client.on('presenceUpdate', (oldPresence, newPresence) =>
# Client#reconnecting
The client.reconnecting
event has been removed in favor of the client.shardReconnecting
event to make use of internal sharding.
- client.on('reconnecting', () => console.log('Successfully reconnected.'));
+ client.on('shardReconnecting', id => console.log(`Shard with ID ${id} reconnected.`));
# Client#resume
The client.resume
event has been removed in favor of the client.shardResume
event to make use of internal sharding.
- client.on('resume', replayed => console.log(`Resumed connection and replayed ${replayed} events.`));
+ client.on('shardResume', (replayed, shardID) => console.log(`Shard ID ${shardID} resumed connection and replayed ${replayed} events.`));
# Client#status
The client.status
property has been removed and is now in the WebSocketManager
class. In addition, it is no longer a getter.
- client.status;
+ client.ws.status;
# Client#syncGuilds
client.syncGuilds()
has been removed entirely, along with all other user account-only properties and methods.
# Client#typingStop
The client.typingStop
event has been removed entirely, as it was an event created by the library and not an actual Discord WebSocket event.
# Client#userNoteUpdate
The client.userNoteUpdate
event has been removed entirely, along with all other user account-only properties and methods.
# Client#users
client.users
has been changed from a Collection to a Manager.
# Client#voiceConnections
client.voiceConnections
has been removed and is now in the ClientVoiceManager
class. In addition, the Collection
is no longer a getter.
- client.voiceConnections;
+ client.voice.connections;
# Client#voiceStateUpdate
The client.voiceStateUpdate
event now returns oldState
and newState
representing the VoiceState
of the member before and after the update, as opposed to the member itself.
- client.on('voiceStateUpdate', (oldMember, newMember) => console.log(oldMember));
+ client.on('voiceStateUpdate', (oldState, newState) => console.log(oldState));
# ClientOptions
There have been several changes made to the ClientOptions
object located in client#options
.
# ClientOptions#apiRequestMethod
clientOptions.apiRequestMethod
has been made sequential and is used internally.
# ClientOptions#shardId
clientOptions.shardId
has been changed to clientOptions.shards
and now also accepts an array of numbers.
- options.shardId: 1
+ options.shards: [1, 2, 3]
# ClientOptions#shards
clientOptions.shards
has been removed and is functionally equivalent to clientOptions.shardCount
on v12.
# ClientOptions#sync
clientOptions.sync
has been removed entirely, along with all other user account-only properties and methods.
# ClientOptions#disabledEvents
clientOptions.disabledEvents
has been removed in favor of using intents. Please refer to our more detailed article about this topic
# ClientUser
# ClientUser#acceptInvite
clientUser.acceptInvite()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#addFriend
clientUser.addFriend()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#avatarURL
clientUser.avatarURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return. The dynamic
option allows you to always get a .gif
file for animated avatars. Otherwise the returned link will fall back to the format specified in the format
option or .webp
(it's default) if none is provided.
- clientUser.avatarURL;
+ clientUser.avatarURL();
+ clientUser.avatarURL({ dynamic: true, format: 'png', size: 1024 });
# ClientUser#block
clientUser.block()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#blocked
clientUser.blocked
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#createGuild
clientUser.createGuild()
has been removed and transformed in the shape of a Manager. In addition, the second and third parameters in clientUser.createGuild()
have been changed/removed, leaving it with a total of two parameters. The region
and icon
parameters from v11 have been merged into an object as the second parameter.
- clientUser.createGuild('New server', 'us-east', './path/to/file.png');
+ client.guilds.create('New server', { region: 'us-east', icon: './path/to/file.png' });
# ClientUser#displayAvatarURL
clientUser.displayAvatarURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return. If the dynamic
option is provided you will receive a .gif
URL if the image is animated, otherwise it will fall back to the specified format
or its default .webp
if none is provided.
- clientUser.displayAvatarURL;
+ clientUser.displayAvatarURL();
+ clientUser.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 });
# ClientUser#email
clientUser.email
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#fetchMentions
clientUser.fetchMentions()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#fetchProfile
clientUser.fetchProfile()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#friends
clientUser.friends
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#guildSettings
clientUser.guildSettings
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#mfaEnabled
clientUser.mfaEnabled
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#mobile
clientUser.mobile
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#note
clientUser.note
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#notes
clientUser.notes
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#premium
clientUser.premium
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#removeFriend
clientUser.removeFriend()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#send***
Just like the TextChannel#send***
methods, all the .send***()
methods have been removed in favor of one general .send()
method. Read through the TextChannel#send*** section for more information.
# ClientUser#setGame
clientUser.setGame()
has been changed to clientUser.setActivity()
. The second parameter is no longer for providing a streaming URL, but rather an object that allows you to provide the URL and activity type.
- clientUser.setGame('with my bot friends!');
+ clientUser.setActivity('with my bot friends!');
- clientUser.setGame('with my bot friends!', 'https://twitch.tv/your/stream/here');
+ clientUser.setActivity('with my bot friends!', { url: 'https://twitch.tv/your/stream/here', type: 'STREAMING' });
# ClientUser#setNote
clientUser.setNote()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#setPassword
clientUser.setPassword()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#settings
clientUser.settings
has been removed entirely, along with all other user account-only properties and methods.
# ClientUser#unblock
clientUser.unblock()
has been removed entirely, along with all other user account-only properties and methods.
# ClientUserChannelOverride
The ClientUserChannelOverride
class has been removed entirely, along with all other user account-only properties and methods.
# ClientUserGuildSettings
The ClientUserGuildSettings
class has been removed entirely, along with all other user account-only properties and methods.
# ClientUserSettings
The ClientUserSettings
class has been removed entirely, along with all other user account-only properties and methods.
# ClientUserChannelOverride
The ClientUserChannelOverride
class has been removed entirely.
# ClientUserGuildSettings
The ClientUserGuildSettings
class has been removed entirely.
# ClientUserSettings
The ClientUserSettings
class has been removed entirely.
# Collection
# Collection#find/findKey
Both methods will now return undefined
if nothing is found.
# Collection#deleteAll
collection.deleteAll()
has been removed in favor of map's default clear()
method.
- roles.deleteAll();
+ roles.clear();
# Collection#exists
collection.exists()
has been removed entirely in favor of collection.some()
- client.users.exists('username', 'Bob');
+ client.users.cache.some(user => user.username === 'Bob');
# Collection#filterArray
collection.filterArray()
has been removed completely.
# Collection#findAll
collection.findAll()
has been removed completely as the same functionality can be obtained through collection.filter()
.
# Collection#first/firstKey/last/lastKey/random/randomKey
The amount
parameter of these methods now allows a negative number which will start the query from the end of the collection instead of the start.
# Collection#tap
collection.tap
runs a specific function over the collection instead of mimicking <array>.forEach()
, this functionality was moved to collection.each()
.
# Collector
# Collector#cleanup
collector.cleanup()
has been removed entirely.
# Collector#handle
collector.handle()
has been changed to collector.handleCollect()
.
# Collector#postCheck
collector.postCheck()
has been changed to collector.checkEnd()
.
# DMChannel
# DMChannel#acknowledge
dmChannel.acknowledge()
has been removed entirely, along with all other user account-only properties and methods.
# DMChannel#createCollector
dmChannel.createCollector()
has been removed in favor of dmChannel.createMessageCollector()
.
# DMChannel#fetch(Pinned)Message(s)
dmChannel.fetchMessage(s)
has been transformed in the shape of a Manager. See the TextChannel#fetch(Pinned)Message(s) section for more information.
# DMChannel#search
dmChannel.search()
has been removed entirely, along with all other user account-only properties and methods.
# DMChannel#send***
Just like the TextChannel#send***
methods, all the .send***()
methods have been removed in favor of one general .send()
method. Read through the TextChannel#send*** section for more information.
# Emoji
Emoji
now extends Base
and represent either a GuildEmoji
or ReactionEmoji
, and some of the specific properties have moved to their respective object, instead of everything on the base Emoji
object.
# Emoji#***RestrictedRole(s)
The helper methods to add and remove a role or roles from the roles allowed to use the emoji are now set via the GuildEmojiRoleManager
.
- emoji.addRestrictedRole('123456789012345678');
- emoji.addRestrictedRoles(['123456789012345678', '098765432109876543']);
- emoji.removeRestrictedRole('1234567890123345678');
- emoji.removedRestrictedRoles(['123456789012345678', '098765432109876543']);
+ emoji.roles.add('123456789012345678');
+ emoji.roles.remove('123456789012345678');
+ emoji.roles.set(['123456789012345678', '098765432109876543']);
# Emoji#deletable
emoji.deletable
has been moved to guildEmoji.deletable
.
# Emoji#fetchAuthor
emoji.fetchAuthor()
has been moved to guildEmoji.fetchAuthor()
.
# Emoji#guild
emoji.guild
has been moved to guildEmoji.guild
.
# Emoji#setName
emoji.setName()
has been moved to guildEmoji.setName()
.
# EvaluatedPermissions
evaluatedPermissions
has been removed entirely, see the Permissions
page.
# Game
The Game
class has been removed in favor of the Activity
class to be consistent with the API. It is also an array of multiple Activities, since a user can have multiple.
- user.presence.game
+ user.presence.activities
# GroupDMChannel
The GroupDMChannel
class has been deprecated from the Discord API. While it's still available through Gamebridge for now, that will also be removed in the future. In addition, group DM's has always been unreliable and hacky to work with a bot.
# Guild
# Guild#acknowledge
guild.acknowledge()
has been removed entirely, along with all other user account-only properties and methods.
# Guild#allowDMs
guild.allowDMs()
has been removed entirely, along with all other user account-only properties and methods.
# Guild#ban
guild.ban()
has been moved to the GuildMemberManager
. In addition, the second parameter in guild.members.ban()
has been changed. The options
parameter no longer accepts a number, nor a string.
- guild.ban(user, 7);
+ guild.members.ban(user, { days: 7 });
- guild.ban(user, 'Too much trolling');
+ guild.members.ban(user, { reason: 'Too much trolling' });
# Guild#Channels
guild.channels
is now a Manager instead of a Collection.
# Guild#createChannel
guild.createChannel()
has been transformed in the shape of a Manager. The second, third and fourth parameters in guild.createChannel()
have been changed/removed, leaving it with a total of two parameters, the second one being an object with all of the options available in ChannelData
.
- guild.createChannel('new-channel', 'text', permissionOverwriteArray, 'New channel added for fun!');
+ guild.channels.create('new-channel', { type: 'text', permissionOverwrites: permissionOverwriteArray, reason: 'New channel added for fun!' });
# Guild#createEmoji
guild.createEmoji()
has been transformed in the shape of a Manager. The third and fourth parameters in guild.createEmoji()
have been changed/removed, leaving it with a total of three parameters. The roles
and reason
parameters from v11 have been merged into an object as the third parameter.
- guild.createEmoji('./path/to/file.png', 'NewEmoji', collectionOfRoles, 'New emoji added for fun!');
+ guild.emojis.create('./path/to/file.png', 'NewEmoji', { roles: collectionOfRoles, reason: 'New emoji added for fun!' });
# Guild#createRole
guild.createRole()
has been transformed in the shape of a Manager. The first and second parameters in guild.createRole()
have been changed/removed, leaving it with a total of one parameter. The data
and reason
parameters from v11 have been moved into an object as the first parameter.
- guild.createRole(roleData, 'New staff role!');
+ guild.roles.create({ data: roleData, reason: 'New staff role!' });
# Guild#deleteEmoji
Guild.deleteEmoji()
has been removed and transformed in the shape of a Manager. Note the possible use of resolve()
as a broader alternative to get()
.
- guild.deleteEmoji('123456789012345678');
+ guild.emojis.resolve('123456789012345678').delete();
# Guild#defaultChannel
Unfortunately, "default" channels don't exist in Discord anymore, and as such, the guild.defaultChannel
property has been removed with no alternative.
Q: "I previously had a welcome message system (or something similar) set up using that property. What can I do now?"
A: There are a few ways to tackle this. Using the example of a welcome message system, you can:
- Set up a database table to store the channel ID in a column when someone uses a
!welcome-channel #channel-name
command, for example. Then inside theguildMemberAdd
event, useclient.channels.cache.get('id')
and send a message to that channel. This is the most reliable method and gives server staff freedom to rename the channel as they please. - Make a new command that creates a
welcome-messages
channel, useguild.channels.cache.find(channel => channel.name === 'welcome-messages')
, and send a message to that channel. This method will work fine in most cases, but will break if someone on that server decides to rename the channel. This may also give you unexpected results, due to Discord allowing multiple channels to have the same name.
TIP
Not sure how to set up a database? Check out this page!
# Guild#emojis
guild.emojis
has been transformed in the shape of a Manager.
# Guild#fetchBans
guild.fetchBans()
will return a Collection
of objects in v12, whereas v11 would return a Collection
of User
objects.
- guild.fetchBans().then(bans => console.log(`${bans.first().tag} was banned`));
+ guild.fetchBans().then(bans => console.log(`${bans.first().user.tag} was banned because "${bans.first().reason}"`));
# Guild#fetchMember(s)
guild.fetchMember()
and guild.fetchMembers()
were both removed and transformed in the shape of Managers. In addition, guild.members.fetch()
will return a Collection
of GuildMember
objects in v12, whereas v11 would return a Guild
object.
- guild.fetchMember('123456789012345678');
+ guild.members.fetch('123456789012345678');
- guild.fetchMembers();
+ guild.members.fetch();
# Guild#iconURL
guild.iconURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return. If the dynamic
option is provided you will receive a .gif
URL if the image is animated, otherwise it will fall back to the specified format
or its default .webp
if none is provided.
- guild.iconURL;
+ guild.iconURL();
+ guild.iconURL({ format: 'png', dynamic: true, size: 1024 });
# Guild#messageNotifications
guild.messageNotifications
has been removed entirely, along with all other user account-only properties and methods.
# Guild#mobilePush
guild.mobilePush
has been removed entirely, along with all other user account-only properties and methods.
# Guild#muted
guild.muted
has been removed entirely, along with all other user account-only properties and methods.
# Guild#position
guild.position
has been removed entirely, along with all other user account-only properties and methods.
# Guild#presences
guild.presences
is now a Manager instead of a Collection.
# Guild#pruneMembers
guild.pruneMembers()
has been transformed in the shape of a Manager. In addition, the first, second, and third parameters in the method have been changed or removed, leaving it with a total of one parameter. The days
, dry
, and reason
parameters from v11 have been merged into an object as the first parameter.
- guild.pruneMembers(7, true, 'Scheduled pruning');
+ guild.members.prune({ days: 7, dry: true, reason: 'Scheduled pruning' });
# Guild#roles
guild.roles
is now a Manager instead of a Collection.
# Guild#search
guild.search()
has been removed entirely, along with all other user account-only properties and methods.
# Guild#setChannelPosition
guild.setChannelPosition()
has been removed entirely. As an alternative, you can use channel.setPosition()
, or guild.setChannelPositions()
, which accepts accepts the same form of data as guild.setChannelPosition
but inside an array.
- guild.setChannelPosition({ channel: '123456789012345678', position: 1 });
+ guild.setChannelPositions([{ channel: '123456789012345678', position: 1 }]);
+ channel.setPosition(1);
# Guild#setPosition
guild.setPosition()
has been removed entirely, along with all other user account-only properties and methods.
# Guild#setRolePosition
guild.setRolePosition()
has been removed entirely as an extraneous helper method. As an alternative, you can use role.setPosition()
.
- guild.setRolePosition({ role: '123456789012345678', position: 1 });
+ role.setPosition(1);
# Guild#splashURL
guild.splashURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return.
- guild.splashURL;
+ guild.splashURL();
+ guild.splashURL({ format: 'png', size: 1024 });
# Guild#suppressEveryone
guild.suppressEveryone
has been removed entirely, along with all other user account-only properties and methods.
# Guild#sync
guild.sync()
has been removed entirely, along with all other user account-only properties and methods.
# Guild#unban
guild.unban()
has been transformed in the shape of a Manager and is now a method on GuildMemberManager
. In addition, it also now optionally accepts a string as a second parameter for reason
.
- guild.unban('123456789012345678');
+ guild.members.unban('123456789012345678', 'Ban appealed.');
# Guild#verificationLevel
guild.verificationLevel
now returns one of "NONE"
, "LOW"
, "MEDIUM"
, "HIGH"
, "VERY_HIGH"
instead of the corresponding number.
# GuildChannel
The properties of a channel relating to its position have been renamed. guildChannel.calculatedPosition
is now guildChannel.position
. guildChannel.position
is now more clearly named guildChannel.rawPosition
to denote that it's directly from the API without any sorting.
- channel.calculatedPosition;
+ channel.position;
- channel.position;
+ channel.rawPosition;
# GuildChannel#clone
The first, second, third, and fourth parameters in channel.clone()
have been changed/removed, leaving it with a total of one parameter. The name
, withPermissions
, withTopic
, and reason
parameters from v11 have been merged into an object as the first parameter. Several other parameters have also been added to the options object.
# GuildChannel#createInvite
The second parameter in channel.createInvite()
has been removed, leaving it with a total of one parameter. The reason
parameter from v11 has been merged into an object as the first parameter.
- channel.createInvite({ temporary: true }, 'Just testing');
+ channel.createInvite({ temporary: true, reason: 'Just testing' });
# GuildChannel#members
guildChannel.members
has been removed from guildChannel.members
and added to textChannel.members
and voiceChannel.members
.
# GuildChannel#messageNotifications
guildChannel.messageNotifications
has been removed entirely, along with all other user account-only properties.
# GuildChannel#muted
guildChannel.muted
has been removed entirely, along with all other user account-only properties.
# GuildChannel#overwritePermissions
guildChannel.overwritePermissions
has been changed to act as replacement for guildChannel.replacePermissionOverwrites
.
The old functionality is moved to guildChannel.updateOverwrite
and guildChannel.createOverwrite
- message.channel.overwritePermissions(message.author, {
- SEND_MESSAGES: false
- })
+ message.channel.createOverwrite(message.author, {
+ SEND_MESSAGES: false
+ })
# GuildChannel#***Permissions
guildChannel.memberPermissions
and guildChannel.rolePermissions
are now private.
# GuildChannel#replacePermissionOverwrites
guildChannel.replacePermissionOverwrites
has been renamed to guildChannel.overwritePermissions
. Overwrites and reason are no longer provided Through an options object, but directly as method arguments.
- channel.replacePermissionOverwrites({
- overwrites: [
- {
- id: message.author.id,
- denied: ['VIEW_CHANNEL'],
- },
- ],
- reason: 'Needed to change permissions'
- });
+ channel.overwritePermissions([
+ {
+ id: message.author.id,
+ deny: ['VIEW_CHANNEL'],
+ },
+ ], 'Needed to change permissions');
# GuildChannel#setPosition
The second parameter in channel.setPosition()
has been changed. The relative
parameter from v11 has been merged into an object.
- channel.setPosition(10, true);
+ channel.setPosition(10, { relative: true, reason: 'Basic organization' });
# GuildMember
# GuildMember***Role(s)
All of the methods to modify a member's roles have been moved to the GuildMemberRoleManager
.
- guildMember.addRole('123456789012345678');
- guildMember.addRoles(['123456789012345678', '098765432109876543']);
+ guildMember.roles.add('123456789012345678');
+ guildMember.roles.add(['123456789012345678', '098765432109876543']);
- guildMember.removeRole('123456789012345678');
- guildMember.removeRoles(['123456789012345678', '098765432109876543']);
+ guildMember.roles.remove('123456789012345678');
+ guildMember.roles.remove(['123456789012345678', '098765432109876543']);
- guildMember.setRoles(['123456789012345678', '098765432109876543']);
+ guildMember.roles.set(['123456789012345678', '098765432109876543']);
# GuildMember#ban
guildMember.ban()
has been transformed in the shape of a Manager and is now a method on GuildMemberManager
. The second parameter has been changed from a string or an object to only accept an object. The reason
and days
parameters are keys in the options
object.
- member.ban(user, 7);
+ guild.members.ban(user, { days: 7 });
- member.ban(user, 'Too much trolling');
+ guild.members.ban(user, { reason: 'Too much trolling' });
# GuildMember#***Role
guildMember.colorRole
, guildMember.highestRole
and guildMember.hoistRole
have all been moved to the GuildMemberRoleManager
.
- guildMember.colorRole;
+ guildMember.roles.color;
- guildMember.highestRole;
+ guildMember.roles.highest;
- guildMember.hoistRole;
+ guildMember.roles.hoist;
# GuildMember#***deaf
guildMember.deaf
, guildMember.selfDeaf
and guildMember.serverDeaf
have all been moved to the VoiceState
class.
- guildMember.deaf;
+ guildMember.voice.deaf;
- guildMember.selfDeaf;
+ guildMember.voice.selfDeaf;
- guildMember.serverDeaf;
+ guildMember.voice.serverDeaf;
# GuildMember#hasPermission
The explicit
parameter has been removed entirely. The checkAdmin
and checkOwner
parameters have been changed into a single options
object with those values as keys.
- guildMember.hasPermission('MANAGE_MESSAGES', true, false, false);
+ guildMember.hasPermission('MANAGE_MESSAGES', { checkAdmin: false, checkOwner: false });
# GuildMember#hasPermissions
guildMember.hasPermissions()
has been removed in favor of guildMember.hasPermission()
.
- guildMember.hasPermissions(['MANAGE_MESSAGES', 'MANAGE_ROLES']);
+ guildMember.hasPermission(['MANAGE_MESSAGES', 'MANAGE_ROLES']);
# GuildMember#lastMessage
The guildMember.lastMessage
property is now read-only.
# GuildMember#missingPermissions
guildMember.missingPermissions
has been removed entirely.
# GuildMember#***mute
guildMember.mute
, guildMember.selfMute
and guildMember.serverMute
have all been moved to the VoiceState
class.
- guildMember.mute;
+ guildMember.voice.mute;
- guildMember.selfMute;
+ guildMember.voice.selfMute;
- guildMember.serverMute;
+ guildMember.voice.serverMute;
# GuildMember#roles
guildMember.roles
is now a Manager instead of a Collection.
# GuildMember#send***
Just like the textChannel#send***
methods, all the .send***()
methods have been removed in favor of one general .send()
method. Read through the textChannel#send*** section for more information.
# GuildMember#set***
Along with the rest of the voice-related methods and properties, the methods for moving, muting and deafening a member have been moved to the VoiceState
class.
- guildMember.setDeaf(true);
+ guildMember.voice.setDeaf(true);
- guildMember.setMute(true);
+ guildMember.voice.setMute(true);
- guildMember.setVoiceChannel('123456789012345678');
+ guildMember.voice.setChannel('123456789012345678');
- guildMember.setVoiceChannel(null);
+ guildMember.voice.kick();
# GuildMember#speaking
guildMember.speaking
has been moved to the VoiceState
class.
- guildMember.speaking;
+ guildMember.voice.speaking;
# GuildMember#voice***
guildMember.voiceChannel
, guildMember.voiceChannelID
and guildMember.voiceSessionID
have all been moved to the VoiceState
class, which is read-only.
- guildMember.voiceChannel;
+ guildMember.voice.channel;
- guildMember.voiceChannelID;
+ guildMember.voice.channelID;
- guildMember.voiceSessionID;
+ guildMember.voice.sessionID;
# Invite
# Invite#***ChannelCount
invite.textChannelCount
and invite.voiceChannelCount
have both been removed entirely.
# Message
# Message#acknowledge
message.acknowledge()
has been removed entirely, along with all other user account-only properties and methods.
# Message#clearReactions
message.clearReactions()
has been transformed in the shape of a Manager.
- message.clearReactions();
+ message.reactions.removeAll();
# Message#delete
The first parameter in message.delete()
has been changed. The timeout
parameter from v11 have been merged into an object as the first parameter. In addition, there is now another optional key in the object, reason
.
- message.delete(5000);
+ message.delete({ timeout: 5000, reason: 'It had to be done.' });
# Message#editCode
In the same sense that the channel.sendCode()
method was removed, message.editCode()
has also been removed entirely.
- message.editCode('js', 'const version = 11;');
+ message.edit('const version = 12;', { code: 'js' });
# Message#hit
message.hit
has been removed entirely, as it was used for user-account only searches.
# Message#is(Member)Mentioned
message.isMentioned()
and message.isMemberMentioned()
have been removed in favor of message.mentions.has()
.
- message.isMentioned('123456789012345678');
- message.isMemberMentioned('123456789012345678');
+ message.mentions.has('123456789012345678');
# Message#member
message.member
is now read-only.
# MessageAttachment
The MessageAttachment
class constructor parameters have changed to reflect that Attachment
has been removed and rolled into MessageAttachment
.
# MessageAttachment#client
attachment.client
has been removed entirely so an attachment can be constructed without needing the full client.
# MessageAttachment#filename
attachment.filename
has been renamed to attachment.name
.
# MessageAttachment#filesize
attachment.filesize
has been renamed to attachment.size
.
# MessageCollector
See the Collector
section for most of the changes to MessageCollector
, such as the new dispose
method and event. Changes to the MessageCollector
constructor in particular are as follows:
# MessageCollector#channel
A GroupDMChannel
is no longer able to be used for a collector, only DMChannel
and TextChannel
.
# MessageCollector#message
The messageCollector.message
event has been removed in favor of the generic collector.on
event.
# MessageCollectorOptions
# MessageCollectorOptions#max(Matches)
The max
and maxMatches
properties of the MessageCollector
class have been renamed and repurposed.
- `max`: The The maximum amount of messages to process.
+ `maxProcessed`: The maximum amount of messages to process.
- `maxMatches`: The maximum amount of messages to collect.
+ `max`: The maximum amount of messages to collect.
# MessageEmbed
MessageEmbed
now encompasses both the received embeds in a message and the constructor - the RichEmbed
constructor was removed in favor of MessageEmbed
.
# MessageEmbed#addBlankField
messageEmbed.addBlankField()
has been removed entirely. To add a blank field, use messageEmbed.addField('\u200b', '\u200b')
.
# MessageEmbed#attachFiles
RichEmbed.attachFile()
has been removed in favor of MessageEmbed.attachFiles()
method, which works for one or more files.
# MessageEmbed#client
messageEmbed.client
has been removed entirely so a new embed can be constructed without needing the full client.
# MessageEmbed#message
messageEmbed.message
has been removed entirely so a new embed can be constructed without needing the full client.
# MessageMentions
# MessageMentions#has
mentions.has()
has been added, replacing message.isMentioned()
and message.isMemberMentioned()
. It has two paramets: the first is data
representing a User
, GuildMember
, Role
, or GuildChannel
and an optional options
object.
- message.isMentioned('123456789012345678');
- message.isMemberMentioned('123456789012345678');
+ message.mentions.has('123456789012345678');
+ message.mentions.has('123456789012345678', { ignoreDirect: true, ignoreRoles: true, ignoreEveryone: true });
# MessageReaction
# MessageReaction#fetchUsers
messageReaction.fetchUsers()
has been transformed in the shape of a Manager. In addition, the first parameter has been removed in favor of an object.
- reaction.fetchUsers(50);
+ reaction.users.fetch({ limit: 50 });
# MessageReaction#remove
messageReaction.remove()
has been transformed in the shape of a Manager.
- reaction.remove();
+ reaction.users.remove();
# OAuth2Application
The OAuth2Application
class has been renamed to ClientApplication
.
# OAuth2Application#bot
application.bot
has been removed entirely.
# OAuth2Application#flags
application.flags
has been removed entirely.
# OAuth2Application#iconURL
application.iconURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return.
- application.iconURL;
+ application.iconURL();
+ application.iconURL({ format: 'png', size: 1024 });
# OAuth2Application#redirectURLs
application.redirectURLs
has been removed entirely.
# OAuth2Application#reset
application.reset()
has been removed entirely, as it was an endpoint for user accounts.
# OAuth2Application#rpcApplicationState
application.rpcApplicationState
has been removed entirely.
# OAuth2Application#secret
application.secret
has been removed entirely.
# PartialGuild(Channel)
The PartialGuild
and PartialGuildChannel
classes for use with invites have been removed entirely.
# Permissions
# Permissions#_member
permissions._member
has been removed entirely.
# Permissions#flags
The following permission flags have been renamed:
READ_MESSAGES
->VIEW_CHANNEL
EXTERNAL_EMOJIS
->USE_EXTERNAL_EMOJIS
MANAGE_ROLES_OR_PERMISSIONS
->MANAGE_ROLES
# Permissions#hasPermission(s)
permissions.hasPermission()
and permissions.hasPermissions()
have been removed entirely in favor of permissions.has()
. This change reduces extraneous helper methods.
# Permissions#missingPermissions
permissions.missingPermissions()
has been renamed to permissions.missing()
and also refactored. The second parameter in v11 was named explicit
, described as "Whether to require the user to explicitly have the exact permissions", defaulting to false
. However, the second parameter in v11 is named checkAdmin
, described as "Whether to allow the administrator permission to override", defaulting to true
.
- permissions.missingPermissions(['MANAGE_SERVER']);
+ permissions.missing(['MANAGE_SERVER']);
# Permissions#raw
permissions.raw
has been removed in favor of permissions.bitfield
.
- permissions.raw;
+ permissions.bitfield;
# Permissions#resolve
permissions.resolve()
has been removed entirely.
# Presence
# Presence#game
presence.game
has been removed in favor of the Activity
class. It is now an array of Activities.
- presence.game;
+ presence.activities;
# RichEmbed
The RichEmbed
class has been removed in favor of the MessageEmbed
class.
# RichEmbed#attachFile
RichEmbed.attachFile()
has been removed in favor of MessageEmbed.attachFiles()
.
- new RichEmbed().attachFile('attachment://file-namme.png');
+ new MessageEmbed().attachFiles(['attachment://file-namme.png']);
- new RichEmbed().attachFile({ attachment: './file-name.png' });
+ new MessageEmbed().attachFiles([{ attachment: './file-name.png' }]);
- new RichEmbed().attachFile(new Attachment('./file-name.png'));
+ new MessageEmbed().attachFiles([new MessageAttachment('./file-name.png')]);
# RichPresenceAssets
# RichPresenceAssets#***ImageURL
Both properties relating to the rich presence's image URL have been changed to be a method, as opposed to a property. It also allows you to determine the file format and size to return.
- asset.smallImageURL;
- asset.largeImageURL;
+ asset.smallImageURL();
+ asset.largeImageURL({ format: 'png', size: 1024 });
# Role
The properties of a role relating to its position have been renamed. role.calculatedPosition
is now role.position
. role.position
is now more clearly named role.rawPosition
to denote that it's directly from the API without any sorting.
- role.calculatedPosition;
+ role.position;
- role.position;
+ role.rawPosition;
# Role#hasPermission(s)
role.hasPermission()
and role.hasPermissions()
have been removed in favor of permissions.has()
.
- role.hasPermission('MANAGE_MESSAGES');
+ role.permissions.has('MANAGE_MESSAGES');
- role.hasPermissions(['MANAGE_MESSAGES', 'MANAGE_SERVER']);
+ role.permissions.has(['MANAGE_MESSAGES', 'MANAGE_SERVER']);
# Role#serialize
role.serialize()
has been removed as an extraneous helper method.
- role.serialize();
+ role.permissions.serialize();
# Role#setPosition
The optional, second parameter of the role.setPosition()
method has been changed to an object; its keys are relative
(a boolean) and reason
(a string).
- role.setPosition(3, true);
+ role.setPosition(3, { relative: true, reason: 'Needed to be higher.' });
# Shard
The death
and spawn
events for a shard can also include a Worker
in addition to the ChildProcess
that was exited or spawned.
# Shard#args
shard.args
is now a property of the shard and has been removed as a parameter from the constructor.
# Shard#respawn
shard.respawn
now takes a second, optional parameter spawnTimeout
, how long to wait in milliseconds until the shard's Client
becomes ready.
# Shard#spawn
The parameters used in v11 have been removed and replaced with a single, optional parameter, spawnTimeout
.
# ShardClientUtil
In order to make use of workers introduced in Node v10.5.0, a new mode
parameter is available in the constructor.
# ShardClientUtil#id
shardClientUtil.id
has been removed and replaced with shardClientUtil.ids
, which is an array of shard IDs of the current client.
# ShardClientUtil#singleton
shardCLientUtil
now has a second parameter mode
to specify whether it's a process
or worker
.
# ShardingManager
# ShardingManger#_spawn
The private method shardingManager._spawn()
has been removed entirely.
# ShardingManager#createShard
The id
parameter is now optional and defaults to this.shards.size
.
# ShardingManager#launch
The shardingManager.launch
event has been removed entirely and replaced with the shardingManager.shardCreate
event.
# ShardingManager#message
The shardingManager.message
event has been removed from this class and is now on the Shard
class.
# ShardingManager#respawnAll
The waitForReady
parameter has been renamed to spawnTimeout
, and the currentShardIndex
parameter has been removed entirely.
# ShardingManager#spawn
A third, optional parameter spawnTimeout
has been added, specifying how long to wait in miliseconds to wait until the Client
is ready; the default is 30000
.
# StreamDispatcher
StreamDispatcher
now extends WritableStream
from Node, you can see the docs here.
# StreamDispatcher#destroyed
streamDispatcher.destroyed
has been removed entirely.
# StreamDispatcher#end
The end
event has been removed. Please use the native finish
event as documented here.
The end
method is now inherited from WritableStream
as documented here.
# StreamDispatcher#passes
streamDispatcher.passes
has been removed entirely.
# StreamDispatcher#pause
The streamDispatcher.pause
method now takes an optional parameter silence
, to specify whether to play silence while paused to prevent audio glitches. Its value is a boolean
and defaults to false
.
- dispatcher.pause();
+ dispatcher.pause(true);
# StreamDispatcher#stream
The streamDispatcher.stream
property has been removed entirely and has been replaced with the streamDispatcher.broadcast
property, which is the broadcast controlling the stream, if any.
# StreamDispatcher#time
The streamDispatcher.time
property has been renamed to streamDispatcher.streamTime
.
# TextChannel
# TextChannel#acknowledge
Has been removed entirely, along with all other user account-only methods and properties.
# TextChannel#***position
See the GuildChannel section for changes to positions.
# TextChannel#clone
All parameters have been removed and reconfigured into a single object.
- channel.clone(undefined, true, false, 'Needed a clone');
+ channel.clone({ name: undefined, reason: 'Needed a clone' });
# TextChannel#createCollector
textChannel.createCollector()
has been removed entirely in favor of textChannel.createMessageCollector()
.
See this section for changes to the MessageCollector
class.
- channel.createCollector(filterFunction, { maxMatches: 2, max: 10, time: 15000 });
+ channel.createMessageCollector(filterFunction, { max: 2, maxProcessed: 10, time: 15000 });
# TextChannel#createWebhook
The second and third parameters in textChannel.createWebhook()
have been changed/removed, leaving it with a total of two parameters. The avatar
and reason
parameters from v11 have been merged into an object as the second parameter.
- channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg', 'Needed a cool new Webhook');
+ channel.createWebhook('Snek', { avatar: 'https://i.imgur.com/mI8XcpG.jpg', reason: 'Needed a cool new Webhook' });
# TextChannel#memberPermissions
This method is now private.
# TextChannel#rolePermissions
This method is now private.
# TextChannel#search
This method has been removed, along with all other user account-only methods.
# TextChannel#send***
All the .send***()
methods have been removed in favor of one general .send()
method.
- channel.sendMessage('Hey!');
+ channel.send('Hey!');
- channel.sendEmbed(embedVariable);
+ channel.send(embedVariable);
+ channel.send({ embed: embedVariable });
WARNING
channel.send(embedVariable)
will only work if that variable is an instance of the MessageEmbed
class; object literals won't give you the expected result unless your embed data is inside an embed
key.
- channel.sendCode('js', 'const version = 11;');
+ channel.send('const version = 12;', { code: 'js' });
- channel.sendFile('./file.png');
- channel.sendFiles(['./file-one.png', './file-two.png']);
+ channel.send({
+ files: [{
+ attachment: 'entire/path/to/file.jpg',
+ name: 'file.jpg',
+ }]
+ channel.send({
+ files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
+ });
- channel.sendFiles(['./file-one.png', './file-two.png']);
+ channel.send({ files: [{ attachment: './file-one.png' }, { attachment: './file-two.png' }] });
+ channel.send({ files: [new MessageAttachment('./file-one.png'), new MessageAttachment('./file-two.png')] });
# TextChannel#fetch(Pinned)Message(s)
channel.fetchMessage()
, channel.fetchMessages()
, and channel.fetchPinnedMessages()
were all removed and transformed in the shape of Managers.
- channel.fetchMessage('123456789012345678');
+ channel.messages.fetch('123456789012345678');
- channel.fetchMessages({ limit: 100 });
+ channel.messages.fetch({ limit: 100 });
- channel.fetchPinnedMessages();
+ channel.messages.fetchPinned();
# User
# User#addFriend
user.addFriend()
has been removed entirely, along with all other user account-only methods.
# User#avatarURL
user.avatarURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return. If the dynamic
option is provided you will receive a .gif
URL if the image is animated, otherwise it will fall back to the specified format
or its default .webp
if none is provided.
- user.avatarURL;
+ user.avatarURL();
+ user.avatarURL({ format: 'png', dynamic: true, size: 1024 });
# User#block
user.block()
has been removed entirely, along with all other user account-only methods.
# User#displayAvatarURL
user.displayAvatarURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return. If the dynamic
option is provided you will receive a .gif
URL if the image is animated, otherwise it will fall back to the specified format
or its default .webp
if none is provided.
- user.displayAvatarURL;
+ user.displayAvatarURL();
+ user.displayAvatarURL({ format: 'png', dynamic: true, size: 1024 });
# User#fetchProfile
user.fetchProfile()
has been removed entirely, along with all other user account-only methods.
# User#note
user.note
has been removed entirely, along with all other user account-only methods.
# User#removeFriend
user.removeFriend()
has been removed entirely, along with all other user account-only methods.
# User#setNote
user.setNote()
has been removed entirely, along with all other user account-only methods.
# User#send***
Just like the textChannel#send***
methods, all the .send***()
methods have been removed in favor of one general .send()
method. Read through the textChannel#send*** section for more information.
# User#unblock
user.unblock()
has been removed entirely, along with all other user account-only methods.
# UserConnection
The UserConnection
class has been removed entirely, along with all other user account-only properties.
# UserProfile
The UserProfile
class has been removed entirely, along with all other user account-only properties.
# VoiceBroadcast
VoiceBroadcast
now implements PlayInterface
instead of VolumeInterface
.
# VoiceBroadcast#currentTranscoder
This property has been removed entirely.
# VoiceBroadcast#destroy
This method has been removed entirely.
# VoiceBroadcast#dispatchers
This property has been renamed to subscribers
and is no longer read-only.
- broadcast.dispatchers;
+ broadcast.subscribers;
# VoiceBroadcast#end
This event has been removed from the VoiceBroadcast
class and is implemented from the WritableStream
class from Node, which BroadcastDispatcher
implements.
# VoiceBroadcast#error
This event has been moved from the VoiceBroadcast
class to the BroadcastDispatcher
class.
# VoiceBroadcast#pause
This method has been moved from the VoiceBroadcast
class to the BroadcastDispatcher
class.
# VoiceBroadcast#play***
All .play***()
methods have been removed and transformed into a single .play()
method.
# VoiceBroadcast#prism
This property has been removed entirely.
# VoiceBroadcast#resume
This method has been moved from the VoiceBroadcast
class to the BroadcastDispatcher
class.
# VoiceBroadcast#warn
This event has been removed entirely.
# VoiceConnection
The VoiceConnection
class also implements the new PlayInterface
class in addition to extending EventEmitter
from Node.
# VoiceConnection#createReceiver
voiceconnection.createReceiver()
has been removed, there is now a single receiver that be accessed from voiceConnection.receiver
# VoiceConnection#play***
All connection.play***()
methods have been removed in favor of one, flexible .play()
method.
# VoiceConnection#prism
This property has been removed entirely.
# VoiceConnection#receivers
This property has been removed entirely.
# VoiceConnection#sendVoiceStateUpdate
This method has been removed entirely.
# VoiceConnection#set***
Both connection.setSessionID()
and connection.setTokenAndEndpoint()
have been removed entirely.
# VoiceReceiver
# VoiceReceiver#create***Stream
Both the receiver.createOpusStream()
and receiver.createPCMStream()
methods have been condensed into one method, receiver.createStream()
, which also optionally accepts a ReceiveStreamOptions
object for the stream.
- receiver.createOpusStream('123456789012345678');
- receiver.createPCMStream('123456789012345678');
+ receiver.createStream('123456789012345678', { mode: 'opus', end: 'silence' });
# VoiceReceiver#destroy
This method has been removed entirely, refer to StreamDispatcher#destroy
for documentation.
# VoiceReceiver#destroyed
This property has been removed entirely.
# VoiceReceiver#opus
This event has been removed entirely.
# VoiceReceiver#pcm
This event has been removed entirely.
# VoiceReceiver#recreate
This method has been removed entirely.
# VoiceReceiver#voiceConnection
This property has been removed entirely.
# VoiceReceiver#warn
This event has been removed entirely, use the receiver.debug
event instead.
# VoiceRegion
# VoiceRegion#sampleHostname
This property has been removed entirely.
# Webhook
# Webhook#avatarURL
webhook.avatarURL
is now a method, as opposed to a property. It also allows you to determine the file format and size to return. If the dynamic
option is provided you will receive a .gif
URL if the image is animated, otherwise it will fall back to the specified format
or its default .webp
if none is provided.
- webhook.avatarURL;
+ webhook.avatarURL();
+ webhook.avatarURL({ format: 'png', dynamic: true, size: 1024 });
# Webhook#send***
Just like the TextChannel#send***
methods, all the .send***()
methods have been removed in favor of one general .send()
method. Read through the TextChannel#send*** section for more information.
# WebhookClient
The WebhookClient
class now extends BaseClient
and implements Webhook
instead of just extending Webhook
, so a lot of methods and properties are documented there, as opposed to on the client.
# Additions
WARNING
Remember to add examples for the additions.
# Activity
# ActivityFlags
# ActivityOptions
These are options for setting an Activity
.
# APIMessage
# Base
# BaseClient
# BitField
# BroadcastDispatcher
# CategoryChannel
# CategoryChannel#members
Similar to textChannel#members
and voiceChannel#members
, categoryChannel#members
returns a Collection
of GuildMembers
who can see the category, mapped by their ID.
# Channel
# Channel#toString
channel.toString()
was moved from GuildChannel
to Channel
.
# Channel#type
channel.type
now may also return unknown
.
# Client
# Client#clearImmediate
# Client#guildIntegrationsUpdate
# Client#invalidated
# Client#setImmediate
# Client#webhookUpdate
# ClientApplication
This is a not a new class; it was formerly called OAuth2Application
in v11. Changes and deletions to methods and properties are covered above (link needed). Additions are as follow:
# ClientApplication#cover(Image)
ClientApplication.cover
and its associated method ClientApplication.coverImage()
return the URL to the application's cover image, with optional modifiers if applied in the method.
ClientApplication.coverImage({ width: 1024, height: 1024 });
# ClientApplication#fetchAssets
ClientApplication.fetchAssests()
returns a promise that resolves into an array of ClientAsset
objects, each of which contains id
, name
and type
keys.
# ClientOptions
# ClientOptions#partials
clientOptions.partials
has been added to allow for partial structures - see the Partials
section of the guide for more details.
# ClientOptions#retry
clientOptions.retry
has been added to allow a maximum amount of reconnect attempts on 5XX errors.
# ClientOptions#presence
clientOptions.presence
has been added to specify presence data to set upon login.
# ClientVoiceManager
# Collector
# Collector#(handle)Dispose
collector.handleDispose
and collector.dispose()
have been added to remove an element from the collection.
# CollectorOptions
# CollectorOptions#dispose
collectorOptions.dispose
has been added to allow for deleted data to be removed from the collection.
# Manager
The Manager class was added in order to store various data types. Uses include
- RoleManager
- UserManager
- GuildManager
- ChannelManager
- MessageManager
- PresenceManager
- ReactionManager
- GuildEmojiManager
- GuildMemberManager
- GuildChannelManager
- ReactionUserManager
- GuildEmojiRoleManager
- GuildMemberRoleManager
# DiscordAPIError
# DiscordAPIError#httpStatus
The DiscordAPIError#httpStatus
has been added with the 4xx status code that the error returns. See the MDN docs for more details.
# DMChannel
# DMChannel#lastMessage
The message object of the last message in the channel, if one was sent. It is a read-only property.
# DMChannel#lastPin***
Two properties have been added, dmChannel#lastPinAt
(read-only) and dmChannel#lastPinStamp
, which returns the Date and timestamp, respectively, of the last pinned message if one is present.
# Guild
# Guild#createIntegration
guild.createIntegration()
has been added.
# Guild#fetchEmbed
guild.fetchEmbed
has been added.
# Guild#fetchIntegrations
guild.fetchIntegrations()
has been added.
# Guild#fetchVanityCode
guild.fetchVanityCode()
has been added.
# Guild#setEmbed
guild.setEmbed()
has been added.
# Guild#shard(ID)
guild.shard
(read-only) and guild.shardID
have been added, representing the information of the shard the guild is on.
# GuildAuditLogs
# GuildAuditLogs#Actions
auditLogs.Actions()
has been added (static method).
# GuildAuditLogs#Targets
auditLogs.Targets()
has been added (static method).
# GuildChannel
# GuildChannel#createOverwrite
Creates or update an existing overwrite for a user or role. The second parameter is a PermissionOverwriteOption
object; the third, optional parameter is reason
, a string.
channel.createOverwrite(message.author, {
SEND_MESSAGES: false,
});
# GuildChannel#permissionsLocked
guildChannel.permissionsLocked
is a boolean value representing if the permissionOverwrites
of the channel match its parent's permissionOverwrites
.
# GuildChannel#updateOverwrite
Creates or update an existing overwrite for a user or role. The second parameter is a PermissionOverwriteOption
object; the third, optional parameter is reason
, a string.
channel.updateOverwrite(message.author, {
SEND_MESSAGES: false,
});
# GuildChannel#viewable
guildChannel.viewable
is a boolean value representing whether the channel is visible to the client user.
# HTTPError
# Integration
# Message
# Message#activity
message.activity
has been added.
# Message#application
message.application
has been added.
# Message.url
message.url
has been added in order to provide a URL to jump to the message.
# MessageAttachment
# MessageAttachment#setAttachment
attachment.setAttachment()
has been added.
# MessageAttachment#setFile
attachment.setFile()
has been added.
# MessageAttachment#setName
attachment.setName()
has been added.
# MessageEmbed
# MessageEmbed#addFields
MessageEmbed.addFields
has been added to add multiple fields at once (note: Fields have to be passed as EmbedFieldData)
# MessageEmbed#files
MessageEmbed.files
has been added as an array of files in the MessageEmbed
.
# MessageEmbed#length
MessageEmbed.length
has been added. It returns a number
equal to all of the fields, title, description, and footer.
# Permissions
# Permissions#flags
PRIORITY_SPEAKER
has been added.
# PlayInterface
This is a new class to play audio over VoiceConnection
s and VoiceBroadcast
s.
# Presence
# Presence#clientStatus
The new presence.clientStatus
property returns an object with three keys: web
, mobile
and desktop
; their values are a PresenceStatus
string. This property allows you to check which client the member or user is using to access Discord.
# Presence#guild
presence.guild
has been added as a helper property to represent the Guild
the presence belongs to, if applicable.
# Presence#member
presence.member
is a read-only property to represent the GuildMember
the presence belongs to, if applicable.
# Presence#user(ID)
presence.user
(read-only) and presence.userID
are properties to represent a User
and its ID that the presence belongs to. The former can be null if the User
is not cached.
# ReactionCollector
# ReactionCollector#empty
reactionCollector.empty()
has been added as a method to remove all collected reactions from the collector.
# ReactionCollector#key
# ReactionCollector#remove
The new remove
event emits when a collected reaction is un-reacted, if the dispose
option is set to true
# Shard
# Shard#_evals
The private property _evals
has been added to map ongoing promises for calls to shard.eval()
.
# Shard#_fetches
The private property _fetches
has been added to map ongoing promises for calls to shard.fetchClientValues()
.
# Shard#worker
# ShardClientUtil
# ShardClientUtil#client
# ShardClientUtil#parentPort
The message port for the master process, if the mode of the ShardClientUtil
is worker
.
# ShardClientUtil#respawnAll
shardClientUtil.respawnAll()
will request a respawn of all shards. It has three parameters, all of which are optional: shardDelay
, how to long to wait in milliseconds between each shard; respawnDelay
, how long to wait between killing the shard's process or worker and restarting it; and spawnTimeout
, how long to wait in milliseconds for a shard to become ready before moving to the next shard.
# Speaking
The Speaking
class has been added as a data structure to interact with the bitfields present when a GuildMember
is speaking, or in the VoiceConnection#speaking
event.
# StreamDispatcher
# StreamDispatcher#bitrateEditable
# StreamDispatcher#paused***
Two new properties have been added, pausedSince
and pausedTime
, to represent the timestamp when the stream was paused, and how long it's been paused for in milliseconds, respectively.
# StreamDispatcher#set***
Several new methods have been added to adjust various aspects of the stream. Methods marked with a * denote that they're usable only with a compatible Opus stream.
setFEC()
* - whether to forward error correction or not if using a compatible Opus streamsetPLP()
* - sets the expected packet loss percentage if using a compatible Opus streamsetVolume()
- sets the volume relative to the input streamsetVolumeDecibels()
- sets the volume in decibelssetVolumeLogarithmic()
- sets the volume so that a perceived value of0.5
is half the perceived volume, etc.
# StreamDispatcher#volumeChange
A new event listener, it is emitted when a volume change in the stream is detected.
dispatcher.on('volumeChange', (oldVolume, newVolume) => {
console.log(`Volume changed from ${oldVolume} to ${newVolume}.`);
});
# TextChannel
# TextChannel#lastPinTimestamp
TextChannel.lastPinTimestamp
was added.
# TextChannel#lastPinAt
TextChannel.lastPinAt
was added.
# User
# User#lastMessageChannelID
# User#locale
user.locale
has been added.
# Util
# Util#cleanContent
This new method converts all mentions to their equivalent text.
# Util#discordSort
This new method sorts a Collection
by Discord's position and ID.
# Util#flatten
This new method flattens any object. Any Collection
s in the object will be converted to an array of keys.
# Util#resolveColor
This new method resolves a ColorResolvable
into a color number.
# Util#resolveString
THis new method resolves a StringResolvable
into a string.
# Util#Constants
# Constant.Colors
WHITE
and YELLOW
have been added as values.
# VoiceBroadcast
# VoiceBroadcast#dispatcher
This new property represents the master dispatcher - if any - that controls everything played by subscribed dispatchers.
# VoiceChannel
# VoiceChannel#editable
This new property returns a boolean
value whether the client can edit the VoiceChannel
or not, eg. any change to the channel besides moving it via channel.setPosition()
. It differs from channel.manageable
in that it also checks if the client has the CONNECT
permissions for that particular channel.
# VoiceReceiver
# VoiceReceiver#debug
This new event is emitted whenever there is a warning and will emit either with an Error
object or string, depending on what causes it to be emitted.
# VoiceState
# VolumeInterface
# VolumeInterface#volumeEditable
This new property returns a boolean
value whether the client can edit the volume of the stream.
# Webhook
# Webhook#url
This new property returns a string
representing the URL of the webhook, and is read-only.
# WebSocketManager
This new class represents the manager of the websocket connection for the client.
# WebSocketOptions
# WebSocketOptions#intents
This new parameter adds support for Intents, controlling which events you receive from Discord. Please refer to our more detailed article about this topic
# WebSocketShard
This new class represents a Shard
's websocket connection.