Some codemods for discord.js.
Uses jscodeshift to do most of the work in updating your discord.js codebase.
Disclaimer This script does it's best to update your codebase in a way that is not breaking, but some transformers, such as
rename-fetch-vanity-code
, replace the old methods with new methods that function slightly different from the old method, in which case you will still need to do some updating manually. The relevant section from the official discord.js update guide will be linked under every transformer.
$ npx discord.js-codemod <codemod> <paths...>
Applies a `discord.js-codemod` to the specified paths
Positionals:
codemod The name of the codemod [string]
paths Paths to run on [string]
Options:
--version Show version number [boolean]
--help Show help [boolean]
--dry Dry run (no changes are made to files)
[boolean] [default: false]
--print Print transformed files to stdout, useful for development
[boolean] [default: false]
--jscodeshift [string] [default: false]
Examples:
$ npx discord.js-codemod v13.0.0/move-intents src
$ npx discord.js-codemod v13.0.0/all src/commands src/events --dry
To pass more options directly to jscodeshift, use --jscodeshift="..."
. For example:
npx discord.js-codemod --jscodeshift="--run-in-band --verbose=2"
Options to recast's printer can be provided through jscodeshift's printOptions
command line argument. For example:
npx discord.js-codemod --jscodeshift="--printOptions='{\"quote\":\"double\"}'"
Runs every transformer for updating from v12 to v13. Links: Discord.js Guide
npx discord.js-codemod v13.0.0/all <paths...>
Includes the following transformers:
move-ban-reason
move-filter
move-intents
move-respawn-params
move-webhook-client-params
recase-id
remove-disable-mentions
remove-fetch-all-members
remove-message-delete-reason
remove-message-edit-history
remove-resolve-string
remove-user-fetch-before
rename-activity-type
rename-api-message
rename-fetch-vanity-code
rename-fetch-widget
rename-manage-emojis
rename-message-event
rename-nsfw
rename-set-widget
rename-user-flags
rename-voice-kick
replace-buffer
replace-collection-array
replace-delete-timeout
replace-fetch-application
update-add-member
update-broadcast-eval
update-channel-types
update-create-overwrite
update-create-role
update-fetch-ban
update-fetch-invites
update-generate-invite
update-has-permission
update-member
update-message-cache
update-message-reply
update-overwrite-permissions
update-owner
update-respawn-all
update-set-presence
update-spawn
update-to-flags
update-typing
update-update-overwrite
Moves the ban reason into an object. Links: Discord.js Guide
- member.ban('reason')
+ member.ban({ reason: 'reason' })
npx discord.js-codemod v13.0.0/move-ban-reason <paths...>
Moves collector filters into an object. Links: Discord.js Guide
- const collector = message.createReactionCollector(filter, { time: 15000 });
+ const collector = message.createReactionCollector({ filter, time: 15000 });
- const reactions = await message.awaitReactions(filter, { time: 15000 });
+ const reactions = await message.awaitReactions({ filter, time: 15000 });
npx discord.js-codemod v13.0.0/move-filter <paths...>
Moves intents out of the ws
property.
Links: Discord.js Guide
- const client = new Client({ ws: { intents: [Intents.FLAGS.GUILDS] } });
+ const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
npx discord.js-codemod v13.0.0/move-intents <paths...>
Moves Shard#respawn
parameters into an object.
Links: Discord.js Guide
- shard.respawn(500, 30000);
+ shard.respawn({ delay: 500, timeout: 30000 });
npx discord.js-codemod v13.0.0/move-respawn-params <paths...>
Moves WebhookClient
id and token parameters into an object.
Links: Discord.js Guide
- new WebhookClient(id, token, options);
+ new WebhookClient({ id, token }, options);
npx discord.js-codemod v13.0.0/move-webhook-client-params <paths...>
Updates all uses of discord.js properties containing ID
to use Id
. See the guide for the full list of properties affected.
Links: Discord.js Guide
- console.log(guild.ownerID);
+ console.log(guild.ownerId);
npx discord.js-codemod v13.0.0/recase-id <paths...>
Updates all uses of disableMentions
to the equivelent setup of allowedMentions
.
Links: Discord.js Guide
- const client = new Discord.Client({ disableMentions: 'everyone' });
+ const client = new Discord.Client({ allowedMentions: { parse: ['users', 'roles'], repliedUser: true } });
npx discord.js-codemod v13.0.0/remove-disable-mentions <paths...>
Removes the fetchAllMembers
client option.
Links: Discord.js Guide
- new Client({ fetchAllMembers: true, ...options });
+ new Client({ ...options });
npx discord.js-codemod v13.0.0/remove-fetch-all-members <paths...>
Removes the reason
option from Message#delete
and MessageManager#delete
.
Links: Discord.js Guide
- message.delete({ reason: '' });
+ message.delete();
npx discord.js-codemod v13.0.0/remove-message-delete-reason <paths...>
Removes the messageEditHistoryMaxSize
client option.
Links: Discord.js Guide
- new Client({ messageEditHistoryMaxSize: 5, ...options });
+ new Client({ ...options });
npx discord.js-codemod v13.0.0/remove-message-edit-history <paths...>
Removes Util.resolveString
. Discord.js now enforces many of its methods are passed strings instead of resolving to one as before. This is something the script is unable to update.
Links: Discord.js Guide
npx discord.js-codemod v13.0.0/remove-resolve-string <paths...>
Removes the before
option from ReactionUserManager#fetch
.
Links: Discord.js Guide
- reaction.users.fetch({ before: '123456789987654321' });
+ reaction.users.fetch();
npx discord.js-codemod v13.0.0/remove-user-fetch-before <paths...>
Renames CUSTOM_STATUS
to CUSTOM
.
Links: Discord.js Guide
npx discord.js-codemod v13.0.0/rename-activity-type <paths...>
Renames APIMessage
to MessagePayload
.
Links: Discord.js Guide
- APIMessage.create();
+ MessagePayload.create();
npx discord.js-codemod v13.0.0/rename-api-message <paths...>
Replaces Guild#fetchVanityCode
with Guild#fetchVanityData
. You must manually update your code to handle the different return.
Links: Discord.js Guide
- Guild.fetchVanityCode().then(code => console.log(`Vanity URL: https://discord.gg/${code}`));
+ Guild.fetchVanityData().then(res => console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`));
npx discord.js-codemod v13.0.0/rename-fetch-vanity-code <paths...>
Replaces Guild#fetchWidget
with Guild#fetchWidgetSettings
.
Links: Discord.js Guide
- guild.fetchWidget();
+ guild.fetchWidgetSettings();
npx discord.js-codemod v13.0.0/rename-fetch-widget <paths...>
Replaces MANAGE_EMOJIS
with MANAGE_EMOJIS_AND_STICKERS
Links: Discord.js Guide
- Permissions.FLAGS.MANAGE_EMOJIS;
+ Permissions.FLAGS.MANAGE_EMOJIS_AND_STICKERS;
npx discord.js-codemod v13.0.0/rename-manage-emojis <paths...>
Replaces the message
client event with messageCreate
.
Links: Discord.js Guide
- client.on("message", message => { ... });
+ client.on("messageCreate", message => { ... });
npx discord.js-codemod v13.0.0/rename-message-event <paths...>
Replaces Guild#nsfw
with Guild#nsfwLevel
.
Links: Discord.js Guide
- guild.nsfw;
+ guild.nsfwLevel;
npx discord.js-codemod v13.0.0/rename-nsfw <paths...>
Replaces Guild#setWidget
with Guild#setWidgetSettings
.
Links: Discord.js Guide
- guild.setWidget();
+ guild.setWidgetSettings();
npx discord.js-codemod v13.0.0/rename-set-widget <paths...>
Replaces DISCORD_PARTNER
with PARTNERED_SERVER_OWNER
and VERIFIED_DEVELOPER
with EARLY_VERIFIED_BOT_DEVELOPER
.
Links: Discord.js Guide
- user.flags.has(UserFlags.FLAGS.DISCORD_PARTNER)
+ user.flags.has(UserFlags.FLAGS.PARTNERED_SERVER_OWNER)
- user.flags.has(UserFlags.FLAGS.VERIFIED_DEVELOPER)
+ user.flags.has(UserFlags.FLAGS.EARLY_VERIFIED_BOT_DEVELOPER)
npx discord.js-codemod v13.0.0/rename-user-flags <paths...>
Replaces VoiceState#kick
with VoiceState#disconnect
.
Links: Discord.js Guide
- member.voice.kick();
+ member.voice.disconnect();
npx discord.js-codemod v13.0.0/rename-voice-kick <paths...>
Replaces Util.convertToBuffer
and Util.str2ab
with Buffer.from
.
Links: Discord.js Guide
- Util.convertToBuffer('input');
- Util.str2ab('input');
+ Buffer.from('input');
npx discord.js-codemod v13.0.0/replace-buffer <paths...>
Replaces Collection#array
and Collection#keyArray
with equivalents.
Links: Discord.js Guide
- collection.array();
+ [...collection.values()];
- collection.keyArray();
+ [...collection.keys()];
npx discord.js-codemod v13.0.0/replace-collection-array <paths...>
Replaces the timeout
option with an equivalent.
Links: Discord.js Guide
- message.delete({ timeout: 10000 });
+ setTimeout(() => message.delete(), 10000);
npx discord.js-codemod v13.0.0/replace-delete-timeout <paths...>
Replaces Client#fetchApplication
with Client#application
.
Links: Discord.js Guide
- client.fetchApplication().then(application => application.name);
+ client.application.name;
npx discord.js-codemod v13.0.0/replace-fetch-application <paths...>
Replaces Guild#addMember
with GuildMemberManager#add
.
Links: Discord.js Guide
- guild.addMember(user, { accessToken: token });
+ guild.members.add(user, { accessToken: token });
npx discord.js-codemod v13.0.0/update-add-member <paths...>
Replaces the input of ShardClientUtil#broadcastEval
with a function.
Links: Discord.js Guide
- client.shard.broadcastEval('this.guilds.cache.size')
+ client.shard.broadcastEval(client => client.guilds.cache.size);
npx discord.js-codemod v13.0.0/update-broadcast-eval <paths...>
Replaces channel types with the updated versions. Links: Discord.js Guide
- if(channel.type === 'text') channel.send('Content');
+ if(channel.type === 'GUILD_TEXT') channel.send('Content');
npx discord.js-codemod v13.0.0/update-channel-types <paths...>
Replaces GuildChannel#createOverwrite
with PermissionOverwriteManager#create
.
Links: Discord.js Guide
- channel.createOverwrite(user, { VIEW_CHANNEL: false });
+ channel.permissionOverwrites.create(user, { VIEW_CHANNEL: false });
npx discord.js-codemod v13.0.0/update-create-overwrite <paths...>
Unnests the role data and adds the reason
parameter to the object in RoleManager#create
.
Links: Discord.js Guide
- guild.roles.create({ data: { name: "New role" } }, "Creating new role");
+ guild.roles.create({ name: "New role", reason: "Creating new role" })
npx discord.js-codemod v13.0.0/update-create-role <paths...>
Replaces Guild#fetchBan
and Guild#fetchBans
with GuildBanManager#fetch
.
Links: Discord.js Guide
- guild.fetchBan(user);
+ guild.bans.fetch(user);
- guild.fetchBans();
+ guild.bans.fetch();
npx discord.js-codemod v13.0.0/update-fetch-ban <paths...>
Replaces Guild#fetchInvites
with GuildInviteManager#fetch
.
Links: Discord.js Guide
- guild.fetchInvites();
+ guild.invites.fetch();
npx discord.js-codemod v13.0.0/update-fetch-invites <paths...>
Moves the permissions
parameter into an object. Discord.js requires providing either the bot
or applications.commands
scope, which you will have to do manually.
Links: Discord.js Guide
- client.generateInvite([Permissions.FLAGS.SEND_MESSAGES]);
+ client.generateInvite({ scopes: ['bot'], permissions: [Permissions.FLAGS.SEND_MESSAGES] });
npx discord.js-codemod v13.0.0/update-generate-invite <paths...>
Replaces GuildMember#hasPermission
with Permissions#has
.
Links: Discord.js Guide
- member.hasPermission(Permissions.FLAGS.SEND_MESSAGES);
+ member.permissions.has(Permissions.FLAGS.SEND_MESSAGES);
npx discord.js-codemod v13.0.0/update-has-permission <paths...>
Replaces Guild#member
with GuildMemberManager#resolve
.
Links: Discord.js Guide
- guild.member(user);
+ guild.members.resolve(user);
npx discord.js-codemod v13.0.0/update-member <paths...>
Removes the messageCacheMaxSize
client option and adds an equivalent makeCache
.
Links: Discord.js Guide
- new Client({ messageCacheMaxSize: 100 });
+ new Client({ makeCache: Options.cacheWithLimits({ MessageManager: 100 }) });
npx discord.js-codemod v13.0.0/update-message-cache <paths...>
Replaces Guild#member
with GuildMemberManager#resolve
.
Links: Discord.js Guide
- guild.member(user);
+ guild.members.resolve(user);
npx discord.js-codemod v13.0.0/update-member <paths...>
Replaces GuildChannel#overwritePermissions
with PermissionOverwriteManager#set
.
Links: Discord.js Guide
- channel.overwritePermissions([{ id: user.id , allow: ['VIEW_CHANNEL'], deny: ['SEND_MESSAGES'] }]);
+ channel.permissionOverwrites.set([{ id: user.id , allow: ['VIEW_CHANNEL'], deny: ['SEND_MESSAGES'] }]);
npx discord.js-codemod v13.0.0/update-overwrite-permissions <paths...>
Replaces Guild#owner
with Guild#fetchOwner
or Guild#ownerId
.
Links: Discord.js Guide
- console.log(guild.owner);
+ guild.fetchOwner().then(console.log);
- guild.owner.id;
+ guild.ownerId;
npx discord.js-codemod v13.0.0/update-owner <paths...>
Moves ShardClientUtil#respawnAll
parameters into an object.
Links: Discord.js Guide
- client.shard.respawnAll(5000, 500, 30000);
+ client.shard.respawnAll({ shardDelay: 5000, respawnDelay: 500, timeout: 30000 });
npx discord.js-codemod v13.0.0/update-respawn-all <paths...>
Moved activity
into an array called activities
.
Links: Discord.js Guide
- client.user.setPresence({ activity: { name: 'with discord.js' } });
+ client.user.setPresence({ activities: [{ name: 'with discord.js' }] });
npx discord.js-codemod v13.0.0/update-set-presence <paths...>
Moves ShardingManager#spawn
parameters into an object.
Links: Discord.js Guide
- manager.spawn('auto', 5500, 30000);
+ manager.spawn({ amount: 'auto', delay: 5500, timeout: 30000 });
npx discord.js-codemod v13.0.0/update-spawn <paths...>
Changes string literals for bitfield flags to use flags instead. Links: Discord.js Guide
- permissions.has('SEND_MESSAGES')
+ permissions.has(Permissions.FLAGS.SEND_MESSAGES)
npx discord.js-codemod v13.0.0/update-to-flags <paths...>
Changes TextChannel#startTyping
with TextChannel#sendTyping
and removes TextChannel#stopTyping
.
Links: Discord.js Guide
- channel.startTyping();
- wait(10_000);
- channel.stopTyping();
+ channel.sendTyping();
npx discord.js-codemod v13.0.0/update-typing <paths...>
Replaces GuildChannel#updateOverwrite
with PermissionOverwriteManager#edit
.
Links: Discord.js Guide
- channel.updateOverwrite(user, { VIEW_CHANNEL: false });
+ channel.permissionOverwrites.edit(user, { VIEW_CHANNEL: false });
npx discord.js-codemod v13.0.0/update-update-overwrite <paths...>