Skip to content

Package

eslint-plugin-discordjs v0.2.1

Changelog

eslint-plugin-discordjs

Catch discord.js payloads that Discord would reject, before the bot runs.

Changelog · Reference · Discord

npm node bun license

About

eslint-plugin-discordjs has type-aware ESLint rules for discord.js. Apart from the two prefer-* style rules, each rule catches a payload or command definition that discord.js or the Discord API rejects at run time. The rules check values known at lint time.

Install it in any discord.js project. It needs no seedcord package.

seedcord is pre-1.0, so a minor version can break your lint setup. Each release's changelog says what changed and how to update.

Installation

pnpm add -D eslint-plugin-discordjs

Most rules read types, so they need typed linting (projectService). The sample below uses defineConfig from eslint/config, which needs ESLint 9.22 or later.

Usage

// eslint.config.js
import { defineConfig } from 'eslint/config';
import discordjs from 'eslint-plugin-discordjs';
import tseslint from 'typescript-eslint';

export default defineConfig(
    // ...your existing config
    {
        files: ['**/*.ts'],
        extends: [discordjs.configs.recommended],
        languageOptions: {
            parser: tseslint.parser,
            parserOptions: {
                projectService: true,
                tsconfigRootDir: import.meta.dirname
            }
        }
    }
);

If your config already sets up typed linting, leave out the languageOptions block.

Rules

Rule Catches
no-mixed-message-format components v2 builders in the same message as content, embeds, poll, or stickers
require-components-v2-flag v2 components without MessageFlags.IsComponentsV2
select-menu-min-exceeds-max a select menu whose minimum is above its maximum
no-discord-limit-exceeded more items than Discord allows on a builder, like a sixth component in a row or a 26th choice
no-conflicting-button-props button props that don't go together, like a customId with a url
require-button-props a button missing its style or a prop its style needs
no-choices-and-autocomplete autocomplete and static choices on one slash option
required-option-before-optional a required slash option after an optional one
valid-command-name slash command and option names Discord rejects
prefer-ephemeral-flag the deprecated ephemeral: true reply option. Its autofix writes MessageFlags.Ephemeral
prefer-v2-component an embed that components v2 can replace

All rules run at error except the two prefer-* style rules, which warn.

seedcord

A seedcord bot gets these rules through @seedcord/eslint-plugin, whose seedcord preset turns on this plugin's recommended rules plus the seedcord rules.


Part of seedcord · Built by materwelonDhruv