This is a small discord.py soundboard bot with REST-API and webinterface using flask.
I got the initial code with a Tkinther interface from https://github.com/JonasB2510 I changed it so it is using flask as an WebUI with HTTP-Basic-Auth
| Theme | EN Light | EN Dark | DE Light | DE Dark |
|---|---|---|---|---|
| Beige | ![]() |
![]() |
![]() |
![]() |
| Blue | ![]() |
![]() |
![]() |
![]() |
| Cyan | ![]() |
![]() |
![]() |
![]() |
| Default | ![]() |
![]() |
![]() |
![]() |
| Green | ![]() |
![]() |
![]() |
![]() |
| Grey | ![]() |
![]() |
![]() |
![]() |
| Jannik | ![]() |
![]() |
![]() |
![]() |
| Orange | ![]() |
![]() |
![]() |
![]() |
| Pink | ![]() |
![]() |
![]() |
![]() |
| Purple | ![]() |
![]() |
![]() |
![]() |
| Red | ![]() |
![]() |
![]() |
![]() |
| Ugly | ![]() |
![]() |
![]() |
![]() |
| Yellow | ![]() |
![]() |
![]() |
![]() |
$ git clone https://git.absolutely-not-a-virus.de/soundbot/soundbot
$ cd soundbot
$ python3 bot.py
Configure the config by following the commands in the console.
Where to get GuildID
To get the server ID for the first parameter, open Discord, go to Settings → Advanced and enable developer mode. Then, right-click on the server title and select "Copy ID" to get the guild ID.Where to get ChannelID
To get the server ID for the first parameter, open Discord, go to Settings → Advanced and enable developer mode. Then, right-click on the voice channel and select "Copy ID" to get the channel ID.Where to get a bot token
To get a Bot/Bot token first go to https://discord.com/developers/applications and click on new application, type in a name read & agree the TOS & policy. Now on the side click on bot then scroll down and enable "Message Content Intent". Now go to oauth2 on the side. Now select bot > administrator (or "View Channels", "Connect", "Speak"I don't have the htpasswd command
Install the apache2-utils packet. e.g.:$ sudo apt install apache2-utils
Now add sound files to the sounds directory and start the bot with $ python3 bot.py
All API-Endpoints are password protected and require a HTTP Basic Auth header.
1. Get Sounds
- Endpoint:
/api/sounds - Method:
GET - Description: Gets a list of all registered sounds.
Request example:
import requests
from requests.auth import HTTPBasicAuth
response = requests.get(
'http://127.0.0.1:5000/api/sounds',
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())2. Add Sound
- Endpoint:
/api/sounds/add - Method:
POST - Description: Registers a soundfile.
Body example:
{
"name": "example_sound",
"path": "sounds/example_sound.mp3"
}Request example:
import requests
from requests.auth import HTTPBasicAuth
data = {
"name": "example_sound",
"path": "sounds/example_sound.mp3"
}
response = requests.post(
'http://127.0.0.1:5000/api/sounds/add',
json=data,
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())3. Remove Sound
- Endpoint:
/api/sounds/remove - Method:
POST - Description: Unregisters a soundfile.
Body example:
{
"name": "example_sound"
}Request example:
import requests
from requests.auth import HTTPBasicAuth
data = {
"name": "example_sound"
}
response = requests.post(
'http://127.0.0.1:5000/api/sounds/remove',
json=data,
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())4. Rename Sound
- Endpoint:
/api/sounds/rename - Method:
POST - Description: Changes the name of an registrated sound.
Body example:
{
"oldName": "example_sound",
"newName": "new_example_sound"
}Request example:
import requests
from requests.auth import HTTPBasicAuth
data = {
"oldName": "example_sound",
"newName": "new_example_sound"
}
response = requests.post(
'http://127.0.0.1:5000/api/sounds/rename',
json=data,
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())5. Play Sound
- Endpoint:
/api/sounds/play - Method:
POST - Description: Plays a sound.
Body example:
{
"name": "example_sound"
}Request example:
import requests
from requests.auth import HTTPBasicAuth
data = {
"name": "example_sound"
}
response = requests.post(
'http://127.0.0.1:5000/api/sounds/play',
json=data,
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())6. Stop Sound
- Endpoint:
/api/sounds/stop - Method:
POST - Description: Stops the audio.
Request example:
import requests
from requests.auth import HTTPBasicAuth
response = requests.post(
'http://127.0.0.1:5000/api/sounds/stop',
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())7. Join Channel
- Endpoint:
/api/channel/join - Method:
POST - Description: Make the bot join a specific channel.
Body example:
{
"guild_id": "1234567890123456789",
"channel_id": "1234567890123456789"
}Request example:
import requests
from requests.auth import HTTPBasicAuth
data = {
"guild_id": "1234567890123456789",
"channel_id": "1234567890123456789"
}
response = requests.post(
'http://127.0.0.1:5000/api/channel/join',
json=data,
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())8. Leave Channel
- Endpoint:
/api/channel/leave - Method:
POST - Description: Make the bot leave.
Request example:
import requests
from requests.auth import HTTPBasicAuth
response = requests.post(
'http://127.0.0.1:5000/api/channel/leave',
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())9. Update Settings
- Endpoint:
/api/settings - Method:
POST - Description: Changes the settings for
guild_idandchannel_id.
Body example:
{
"guild_id": "1234567890123456789",
"channel_id": "1234567890123456789"
}Request example:
import requests
from requests.auth import HTTPBasicAuth
data = {
"guild_id": "1234567890123456789",
"channel_id": "1234567890123456789"
}
response = requests.post(
'http://127.0.0.1:5000/api/settings',
json=data,
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())10. Get Settings
- Endpoint:
/api/settings - Method:
GET - Description: Gets the current setting of: (
guild_idandchannel_id)
Request example:
import requests
from requests.auth import HTTPBasicAuth
response = requests.get(
'http://127.0.0.1:5000/api/settings',
auth=HTTPBasicAuth('admin', 'password123')
)
print(response.json())Discord Bot Commands
Plays the specified sound in the current voice channel.
Stops the currently playing sound.
Joins the specified voice channel or the channel where the user is currently in.
Leaves the voice channel the bot is connected to.
Lists all the available sounds in the bot.
Watchdog
Monitors the sounds directory for changes (additions or deletions of sound files). Automatically registers or unregisters sound files with the Flask API.Event Handling:
on_created: Adds the new sound file to the registry.
on_deleted: Removes the sound file from the registry.
Configuration
Stores all configuration settings such as sound files, Discord guild ID, channel ID, and Flask server details.Sound Files: A dictionary mapping sound names to their file paths. Guild ID: The ID of the Discord server. Channel ID: The ID of the Discord channel. Discord Token: The token for your Discord bot. Flask Settings: Includes the host, port, username, and password for the Flask server.
{ "sound_files": {}, "guild_id": "your_guild_id", "channel_id": "your_channel_id", "discord_token": "YOUR_DISCORD_TOKEN", "flask": { "host": "127.0.0.1", "port": 5000, "username": "admin", "password": "hashed_password" } }
Flask API Endpoints
Returns a list of all registered sound files.
Adds a new sound file to the registry.
Request Body:
json
{
"name": "sound_name",
"path": "path/to/sound/file"
}
Removes a sound file from the registry.
Request Body:
json
{
"name": "sound_name"
}
Renames an existing sound file in the registry.
Request Body:
json
{
"oldName": "old_sound_name",
"newName": "new_sound_name"
}
Plays a registered sound in the specified Discord channel.
Request Body:
json
{
"name": "sound_name"
}
Joins a specified voice channel in a Discord server.
Request Body:
json
{
"guild_id": "your_guild_id",
"channel_id": "your_channel_id"
}
Leaves the voice channel in the specified Discord server.
Request Body:
json
{
"guild_id": "your_guild_id"
}
Stops the currently playing sound in the specified Discord server.
Request Body:
json
{
"guild_id": "your_guild_id"
}

















































