Updating from v1 to v2
Framework version
# Update chooksie to latest version
$ npm i chooksie@latest
# Upgrade CLI version to latest version
$ npm i @chookscord/cli@latest
# Or if you installed globally
$ npm i -g @chookscord/cli@latest
# Update chooksie to latest version
$ yarn add chooksie@latest
# Upgrade CLI version to latest version
$ yarn add @chookscord/cli@latest
# Or if you installed globally
$ yarn global add @chookscord/cli@latest
# Update chooksie to latest version
$ pnpm add chooksie@latest
# Upgrade CLI version to latest version
$ pnpm add @chookscord/cli@latest
# Or if you installed globally
$ pnpm add -g @chookscord/cli@latest
ES Modules
True ES Module support by setting "type": "module"
in package.json
has been temporarily removed.
Existing ESM-style code (import
/export
) still works, but top-level await and importing packages written in pure ESM are currently not supported.
TIP
To keep track of this feature, visit feat: Reimplement support for true ESM mode
- "type": "module"
Config
Credentials have been simplified and no longer need Application IDs to be defined.
import { defineConfig } from 'chooksie'
export default defineConfig({
- credentials: {
- token: process.env.DISCORD_BOT_TOKEN,
- applicationId: process.env.DISCORD_APP_ID,
- },
+ token: process.env.DISCORD_BOT_TOKEN,
intents: [],
})
import { defineConfig } from 'chooksie'
export default defineConfig({
- credentials: {
- token: process.env.DISCORD_BOT_TOKEN,
- applicationId: process.env.DISCORD_APP_ID,
- },
+ token: process.env.DISCORD_BOT_TOKEN,
intents: [],
})
const { defineConfig } = require('chooksie')
module.exports = defineConfig({
- credentials: {
- token: process.env.DISCORD_BOT_TOKEN,
- applicationId: process.env.DISCORD_APP_ID,
- },
+ token: process.env.DISCORD_BOT_TOKEN,
intents: [],
})
Subcommands
Subcommands were renamed from SubCommand
to Subcommand
.
- const subcommand = defineSubCommand()
+ const subcommand = defineSubcommand()
- const subcommand: ChooksSubCommandOption
+ const subcommand: Subcommand
- const group = defineSubCommandGroup()
+ const group = defineSubcommandGroup()
- const group: ChooksCommandGroupOption
+ const group: SubcommandGroup
Context Commands
Context Commands are now split to User and Message Commands, and the contexts
directory are now split to users
and messages
directories respectively.
Migrating User Commands
- Move user commands to
users
directory - Switch from
defineContextCommand
todefineUserCommand
- Remove the
type
prop (Optional).
Old User Commands
import { defineContextCommand } from 'chooksie'
export default defineContextCommand({
name: 'High Five',
type: 'USER',
async execute(ctx) {
const user = ctx.interaction.user
const target = ctx.interaction.getUser('user', true)
await ctx.interaction.reply(`${user} High Fived ${target}!`)
},
})
import { defineContextCommand } from 'chooksie'
export default defineContextCommand({
name: 'High Five',
type: 'USER',
async execute(ctx) {
const user = ctx.interaction.user
const target = ctx.interaction.getUser('user', true)
await ctx.interaction.reply(`${user} High Fived ${target}!`)
},
})
const { defineContextCommand } = require('chooksie')
module.exports = defineContextCommand({
name: 'High Five',
type: 'USER',
async execute(ctx) {
const user = ctx.interaction.user
const target = ctx.interaction.getUser('user', true)
await ctx.interaction.reply(`${user} High Fived ${target}!`)
},
})
New User Commands
import { defineUserCommand } from 'chooksie'
export default defineUserCommand({
name: 'High Five',
type: 'USER', // You can "type" leave as is, or remove it entirely.
async execute(ctx) {
const user = ctx.interaction.user
const target = ctx.interaction.targetUser
await ctx.interaction.reply(`${user} High Fived ${target}!`)
},
})
import { defineUserCommand } from 'chooksie'
export default defineUserCommand({
name: 'High Five',
type: 'USER', // You can "type" leave as is, or remove it entirely.
async execute(ctx) {
const user = ctx.interaction.user
const target = ctx.interaction.targetUser
await ctx.interaction.reply(`${user} High Fived ${target}!`)
},
})
const { defineUserCommand } = require('chooksie')
module.exports = defineUserCommand({
name: 'High Five',
type: 'USER', // You can "type" leave as is, or remove it entirely.
async execute(ctx) {
const user = ctx.interaction.user
const target = ctx.interaction.targetUser
await ctx.interaction.reply(`${user} High Fived ${target}!`)
},
})
Migrating Message Commands
- Move message commands to
messages
directory - Switch from
defineContextCommand
todefineMessageCommand
- Remove the
type
prop (Optional).
Old Message Commands
import { defineContextCommand } from 'chooksie'
export default defineContextCommand({
name: 'First Word',
type: 'MESSAGE',
async execute(ctx) {
const message = ctx.interaction.options.getMessage('message', true)
const firstWord = message.content.split(' ')[0]
await ctx.interaction.reply(`The first word was: "${firstWord}"`)
},
})
import { defineContextCommand } from 'chooksie'
export default defineContextCommand({
name: 'First Word',
type: 'MESSAGE',
async execute(ctx) {
const message = ctx.interaction.options.getMessage('message', true)
const firstWord = message.content.split(' ')[0]
await ctx.interaction.reply(`The first word was: "${firstWord}"`)
},
})
const { defineContextCommand } = require('chooksie')
module.exports = defineContextCommand({
name: 'First Word',
type: 'MESSAGE',
async execute(ctx) {
const message = ctx.interaction.options.getMessage('message', true)
const firstWord = message.content.split(' ')[0]
await ctx.interaction.reply(`The first word was: "${firstWord}"`)
},
})
New Message Commands
import { defineMessageCommand } from 'chooksie'
export default defineMessageCommand({
name: 'First Word',
type: 'MESSAGE', // You can "type" leave as is, or remove it entirely.
async execute(ctx) {
const message = ctx.interaction.targetMessage
const firstWord = message.content.split(' ')[0]
await ctx.interaction.reply(`The first word was: "${firstWord}"`)
},
})
import { defineMessageCommand } from 'chooksie'
export default defineMessageCommand({
name: 'First Word',
type: 'MESSAGE', // You can "type" leave as is, or remove it entirely.
async execute(ctx) {
const message = ctx.interaction.targetMessage
const firstWord = message.content.split(' ')[0]
await ctx.interaction.reply(`The first word was: "${firstWord}"`)
},
})
const { defineMessageCommand } = require('chooksie')
module.exports = defineMessageCommand({
name: 'First Word',
type: 'MESSAGE', // You can "type" leave as is, or remove it entirely.
async execute(ctx) {
const message = ctx.interaction.targetMessage
const firstWord = message.content.split(' ')[0]
await ctx.interaction.reply(`The first word was: "${firstWord}"`)
},
})
Options
The following options have been updated:
Old Name | New Name |
---|---|
ChooksOption | Option |
ChooksChoice | Choice |
defineNonCommandOption | defineOption |
ChooksOptionWithChoice | StringOption, NumberOption |
ChooksOptionWithoutChoice | UserOption, BoolOption, ChannelOption, RoleOption, MentionableOption |
ChooksNonCommandOption | NonCommandOption |
Contexts
The following contexts have been updated:
Old Name | New Name |
---|---|
ChooksContext | Context |
ChooksEventContext | EventContext |
ChooksCommandContext | CommandContext |
ChooksContextCommandContext | N/A |
Scripts
defineLifecycle
has been renamed to defineOnLoad
, ChooksLifecycle
is now OnLoad
, and ChooksTeardown
is now removed.
- export const chooksOnLoad = defineLifecycle()
+ export const chooksOnLoad = defineOnLoad()
- export const chooksOnLoad: ChooksLifecycle
+ export const chooksOnLoad: OnLoad
- export function chooksOnLoad(ctx: ChooksContext) {}
+ export function chooksOnLoad(ctx: Context) {}
- const teardown: ChooksTeardown
- exports.chooksOnLoad = defineLifecycle()
+ exports.chooksOnLoad = defineOnLoad()
- exports.chooksOnLoad: ChooksLifecycle
+ exports.chooksOnLoad: OnLoad
- exports.chooksOnLoad = (ctx: ChooksContext) => {}
+ exports.chooksOnLoad = (ctx: Context) => {}
- const teardown: ChooksTeardown
Log Levels
Log levels success
and log
are now removed. Use info
or debug
instead.
- ctx.logger.log('Logging something')
+ ctx.logger.debug('Logging something')
- ctx.logger.success('Ponged!')
+ ctx.logger.info('Ponged!')
Fetch API
The package @chookscord/fetch
has been merged to chooksie/fetch
, and requires undici
to be installed.
Additionally, fetch
is no longer available in Context
objects by default.
# Install undici
$ npm i undici
# Install undici
$ yarn add undici
# Install undici
$ pnpm add undici
import { defineOnLoad } from 'chooksie'
- import { fetch } from '@chookscord/fetch'
+ import { fetch } from 'chooksie/fetch'
export const chooksOnLoad = defineOnLoad(async ctx => {
- await ctx.fetch('https://example.com')
+ await fetch('https://example.com')
})
const { defineOnLoad } = require('chooksie')
- const { fetch } = require('@chookscord/fetch')
+ const { fetch } = require('chooksie/fetch')
exports.chooksOnLoad = defineOnLoad(async ctx => {
- await ctx.fetch('https://example.com')
+ await fetch('https://example.com')
})