https://github.com/neo-ciber94/simple_discordbot
https://github.com/neo-ciber94/simple_discordbot
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/neo-ciber94/simple_discordbot
- Owner: Neo-Ciber94
- License: mit
- Created: 2022-06-26T05:39:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-07T23:00:15.000Z (over 2 years ago)
- Last Synced: 2025-01-06T17:47:07.205Z (9 months ago)
- Language: TypeScript
- Size: 601 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Discord Bot
[![CI][ci_badge]][ci] [![CD][cd_badge]][cd]
[ci]: https://github.com/Neo-Ciber94/simple_discordbot/actions/workflows/ci.yml
[cd]: https://github.com/Neo-Ciber94/simple_discordbot/actions/workflows/cd.yml
[ci_badge]: https://github.com/Neo-Ciber94/simple_discordbot/actions/workflows/ci.yml/badge.svg
[cd_badge]: https://github.com/Neo-Ciber94/simple_discordbot/actions/workflows/cd.yml/badge.svgA simple framework to create events and commands for a discord bot using `discord.js`
## Usage
Rename `.env.sample` to `.env` and add the required values.
Checkout https://discordjs.guide/#before-you-begin for more information.### Creating Commands
To create a new command add it to the `src/commands/` is not required to use the suffix `.command.ts` that's just a convention.
You can use the helper method `createCommand` or implement `ICommand`, both require to export the instance as `default`.> Using `ICommand`
```ts
import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction, CacheType } from "discord.js";
import { ICommand } from "../types/ICommand";class PingCommand implements ICommand {
readonly info = new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with pong!")
.toJSON();async execute(interaction: CommandInteraction) {
await interaction.reply("Pong!");
}
}export default new PingCommand();
```> Using `createCommand`
```ts
import { SlashCommandBuilder } from "@discordjs/builders";
import { createCommand } from "../utils/createCommand";export default createCommand({
info: new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with pong!")
.toJSON(),
execute: (interaction) => interaction.reply("Pong!"),
});
```### Creating Event Listeners
To create an event listener add it to the `src/events/` is not required to use the suffix `.event.ts` that's just other convention. You can use the helper method `createListener` or implement `IEventListener`, both require to export the instance as `default`.
> Using `IEventListener`
```ts
import { Message } from "discord.js";
import { DiscordBotContext } from "../core/discordbot";
import { IEventListener } from "../types/IEventListener";class EchoEventListener implements IEventListener<"messageCreate"> {
readonly event = "messageCreate";async execute(
context: DiscordBotContext,
message: Message
): Promise {
const messageAuthorId = message.author.id;
const botUserId = context.client.user?.id;if (messageAuthorId === botUserId) {
return;
}await message.reply(message.content);
}
}export default new EchoEventListener();
```> Using `createListener`
```ts
import { createListener } from "../utils/createListener";export default createListener({
event: "messageCreate",
async execute(context, message) {
const messageAuthorId = message.author.id;
const botUserId = context.client.user?.id;if (messageAuthorId === botUserId) {
return;
}await message.reply(message.content);
},
});
```LICENSE: MIT