An open-source Discord bot made by Feyli
- Slash commands
- Linked database
- Moderation and utility commands
- Automated systems (welcome message, auto role)
- AI integrations
Want to give this bot a try? You can install it to your Discord server by clicking here.
Sun is also available as a user-wide app, which means you can add it to your Discord account and invoke it anywhere!
Sun's code is stored in this repository. I made it public so anyone can check it out and see what a Discord bot looks like from the inside.
You may use some of this code. However, you may not use the code as a whole, and you may not publish this code as your own product. If your code uses a significant portion of mine, credit is required.
I'm Feyli! Get to know me here. You can find all my socials there, so feel free to contact me on any of them—though I prefer Discord, it's really up to you. Can't wait to hear from you! 😊
To run this project, you'll need to add the following environment variables to your .env file:
TOKENOPENAIKEYARCANEDBPASSWORDPOSTGRES_HOSTPOSTGRES_PORTPOSTGRES_DATABASEPOSTGRES_USERPOSTGRES_PASSWORD
Bun loads the .env file automatically. The PostgreSQL settings have no defaults: the bot fails on startup if any of them is missing, so no deployment details live in the repository.
The non-secret configuration (IDs, the Arcane Blades host) lives in src/config.ts, which is gitignored: copy src/config.example.ts to src/config.ts and adjust it.
Install the source code from GitHub
$ git clone https://github.com/feyli/sun.git
$ cd sunThe bot is written in TypeScript and runs on Bun, which executes TypeScript directly (no build step).
Add the required environment variables and the configuration file, then run:
bun install
cp src/config.example.ts src/config.ts
bun run startTo type-check the project:
bun run typecheckCommands are plain objects built by a factory, in the style of the official discord.js guide. Each file default-exports one command, and src/commands/index.ts is the single place new commands get registered.
export default defineSlashCommand({
data: guildsOnly(
new SlashCommandBuilder()
.setName('example')
.setDescription('Does something useful.')
.addStringOption((option) => option.setName('input').setDescription('Some text.').setRequired(true)),
),
category: 'Utility',
cooldown: 5000,
guildOnly: true,
async execute(interaction) {
// `interaction.guild` is non-null here, because guildOnly narrows the type
await interaction.reply(interaction.options.getString('input', true));
},
});Notes on the shape:
datais a builder, not hand-written JSON. Names, lengths and option types are validated when the module loads rather than rejected by Discord at deploy time.guildOnly: trueboth narrowsinteractionto a cached-guild interaction and installs the runtime guard, so guild commands never hand-roll that check.anywhere()/guildsOnly()set the install and context scopes, which otherwise repeat on every command.- No
clientparameter.src/types/discord.d.tsaugments discord.js'sClient, sointeraction.client.dbandinteraction.client.commandsare typed everywhere.
The same factories cover the other interaction kinds: defineMessageCommand, defineUserCommand, defineButton, defineModal and defineEvent. Buttons and modals live in src/components/ and are matched by custom ID.
The bot's own data lives in PostgreSQL, accessed through Drizzle ORM using Bun's native SQL driver. The schema is declared in src/db/schema.ts and migrations live in drizzle/.
bun run db:generate # create a migration from schema changes
bun run db:migrate # apply pending migrations
bun run db:check # verify migrations are consistent
bun run db:studio # browse the dataThe Arcane Blades database is a separate MariaDB instance shared with the Minecraft server plugin. It is intentionally outside the Drizzle setup and is still queried through the mariadb pool.
We have a support and community Discord server! Join it here.
This logo was entirely created by Feyli and is inspired by his own logo. It features a simplified fox, split into two complementary parts. This logo may not be used by anyone, anywhere, without the explicit approval of the author.