Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/retr0327/discord-bot

A simple and multipurpose Discord bot.
https://github.com/retr0327/discord-bot

discord-bot discord-py python3 scheduled-tasks scheduler

Last synced: 12 days ago
JSON representation

A simple and multipurpose Discord bot.

Awesome Lists containing this project

README

        

# **discord-bot**

This project builds a simple Discord bot which was designed to make our Discord life easier and cooler.

## **Features**

- `/echo `: Echo the same message content to the user
- `/ban [reason]`: Ban user
- `/kick [reason]`: Kick user
- `/brodcast `: Send the scheduled message to a channel
- `/unbrodcast `: Remove the scheduled message from a channel
- `/clear `: Clear the chat history of a channel
- `/text_channel `: Create a channel
- `/rm_text_channel `: Delete a channel
- `/send_to `: Send the message to a specific channel

> `[arg]`: optional argument; ``: required arugment

## **Setup**
### 1. Installation

1. Python version
* `python >= 3.10`

2. Clone repository

```bash
git clone [email protected]:Retr0327/discord-bot.git
```

3. Install Requirement

```bash
cd discord-bot && pip install -r requirements.txt
```

### 2. Environment variables
Please create a `.env` file under the current folder `/discord-bot`:

```env
TOKEN=[discord-bot-token]
GUILD=[discord-channel-id]
```

### 3. Start the bot
There are two main ways to run the bot:

- in Python

First make sure you are in the `discord-bot` folder, and then simply run:

```bash
python ./bot/bot.py
```
or
```bash
python -u "./bot/bot.py"
```

- run in Docker

Install Docker, and use the following command to run:

```bash
docker compose up
```

## Commands Guide
> This bot accepts only slash commands

### 1. User related
#### `/echo `
Echo the exact same message content back to the user, providing a response to their original message.

#### `/ban [reason]`
Impose a mute on a particular user, preventing he/she from sending messages in a specified channel. You can optionally supply a `reason` argument to specify the reason for the mute.

#### `/kick [reason]`
Remove a specific user from a channel. You can optionally supply a `reason` argument to specify the reason for kicking he/she out.

### 2. Channel related
#### `/brodcast `
Regularly send messages to a specific channel. Here is the overview of the brodcasting architecture:

```mermaid

flowchart RL
subgraph DB
direction LR
g[("

SQLite
")]
end

B[Schedule request] --> C((Bot event loop))
C -- Trigger callback --> B
C -- Register callback --> DB
DB -- Operation complete --> C
```

When a user broadcasts a message to a particular channel, the Discord bot logs the task in its event loop. Upon restart, the bot examines the database for any pending tasks and incorporates them into the loop if any are found.

#### `/unbrodcast `
Remove the scheduled message from a channel. In other words, the Discord bot will cancel the scheduled task from its event loop.

#### `/clear `
Clear the chat history of a specific channel.

#### `/text_channel `
Create a Discord text channel.

#### `/rm_text_channel `
Delete a Discord text channel.

#### `/send_to `
Send the message to a specific channel.

## Contact Me
If you have any suggestion or question, please do not hesitate to email me at [email protected]