|
| 1 | +# What Is Dis <!-- omit in toc --> |
| 2 | + |
| 3 | +Typescript Discord bot framework aims to be a simple and easy to use framework for creating discord bots. It is built on top of [discord.js](https://discord.js.org/#/) |
| 4 | + |
| 5 | +# Table of Contents <!-- omit in toc --> |
| 6 | + |
| 7 | +# Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install discord.js @softnetics/what-is-dis |
| 11 | +# Or |
| 12 | +yarn add discord.js @softnetics/what-is-dis |
| 13 | +# Or |
| 14 | +pnpm add discord.js @softnetics/what-is-dis |
| 15 | +# Or |
| 16 | +bun add discord.js @softnetics/what-is-dis |
| 17 | +``` |
| 18 | + |
| 19 | +# Usage |
| 20 | + |
| 21 | +```ts |
| 22 | +import { GatewayIntentBits } from '@discordjs/core' |
| 23 | +import { DiscordBot, defineSlashCommandBasic } from '@softnetics/what-is-dis' |
| 24 | + |
| 25 | +const pingCommand = defineSlashCommandBasic({ |
| 26 | + name: 'ping', |
| 27 | + description: 'Ping!', |
| 28 | + options: { |
| 29 | + message: { |
| 30 | + type: 'string', |
| 31 | + description: 'Message to echo back', |
| 32 | + choices: [ |
| 33 | + { name: 'Hello', value: 'hello' }, |
| 34 | + { name: 'World', value: 'world' }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + to: { |
| 38 | + type: 'user', |
| 39 | + description: 'User to ping', |
| 40 | + required: true, |
| 41 | + }, |
| 42 | + }, |
| 43 | + execute: async ({ interaction, body, logger }) => { |
| 44 | + const message = body.message // Type: "hello" | "world" | undefined |
| 45 | + const user = body.to // Type: string (user id) |
| 46 | + logger.info(`Received /ping command with message: ${message} and user: ${user}`) |
| 47 | + await interaction.reply({ |
| 48 | + content: `Pong! ${message} <@${user}>`, |
| 49 | + }) |
| 50 | + }, |
| 51 | +}) |
| 52 | + |
| 53 | +// Create a discord bot instance |
| 54 | +const bot = new DiscordBot({ |
| 55 | + clientId: environment.DISCORD_CLIENT_ID, |
| 56 | + token: environment.DISCORD_TOKEN, |
| 57 | + intents: [ |
| 58 | + GatewayIntentBits.Guilds, |
| 59 | + GatewayIntentBits.GuildMessages, |
| 60 | + GatewayIntentBits.MessageContent, |
| 61 | + ], |
| 62 | + // If this value is set, the bot will only register commands in this guild. It's useful for development. |
| 63 | + developmentGuildId: environment.DISCORD_DEVELOPMENT_GUILD_ID, |
| 64 | + // If this value is set to true, the bot will delete the commands before registering them for `developmentGuildId`. |
| 65 | + refreshCommands: true, |
| 66 | + // Add more slash commands here |
| 67 | + slashCommands: [pingCommand], |
| 68 | + // Customized logger |
| 69 | + loggerOptions: { |
| 70 | + level: 'debug', |
| 71 | + }, |
| 72 | + // This function will be called when the bot is ready |
| 73 | + onReady: ({ logger }) => { |
| 74 | + logger.info('Try to excecute /ping command!') |
| 75 | + }, |
| 76 | + // This function will be called before the bot shuts down |
| 77 | + onShutDown: async ({ logger }) => { |
| 78 | + logger.info('Bot is shutting down!') |
| 79 | + }, |
| 80 | +}) |
| 81 | + |
| 82 | +// Register the given slash commands and listen for the event |
| 83 | +bot.listen() |
| 84 | +``` |
| 85 | + |
| 86 | +# Examples |
| 87 | + |
| 88 | +You can find examples in the [examples](./examples) folder. |
| 89 | + |
| 90 | +- [Ping-pong discord bot](./examples/bun-simple-bot/) |
| 91 | + |
| 92 | +# Features |
| 93 | + |
| 94 | +- [x] Slash commands |
| 95 | + - Input types |
| 96 | + - [x] Subcommands |
| 97 | + - [ ] 🚧 Subcommand groups |
| 98 | + - [x] String |
| 99 | + - [x] Integer |
| 100 | + - [x] Boolean |
| 101 | + - [x] User |
| 102 | + - [x] Channel |
| 103 | + - [x] Role |
| 104 | + - [x] Mentionable |
| 105 | + - [x] Number |
| 106 | + - [x] Attachment |
| 107 | +- [ ] 🚧 Message command with prefix |
| 108 | +- [ ] 🚧 Message components |
| 109 | + - [ ] 🚧 [Action Rows](https://discordjs.guide/message-components/action-rows.html) |
| 110 | + - [ ] 🚧 [Buttons](https://discordjs.guide/message-components/buttons.html) |
| 111 | + - [ ] 🚧 [Select menus](https://discordjs.guide/message-components/select-menus.html) |
| 112 | +- [ ] 🚧 Other components |
| 113 | + - [ ] 🚧 [Modal](https://discordjs.guide/interactions/modals.html#building-and-responding-with-modals) |
| 114 | + - [ ] 🚧 [Context Menu](https://discordjs.guide/interactions/context-menus.html) |
| 115 | +- [ ] 🚧 Emoji reactions |
| 116 | + |
| 117 | +# Contributing |
| 118 | + |
| 119 | +WIP |
| 120 | + |
| 121 | +# License |
| 122 | + |
| 123 | +[MIT](./LICENSE) |
0 commit comments