- Python 46.6%
- CSS 33.5%
- HTML 19.6%
- Dockerfile 0.3%
| .vscode | ||
| config | ||
| interface | ||
| lang | ||
| screenshots | ||
| .dockerignore | ||
| .gitignore | ||
| bot.py | ||
| config_handler.py | ||
| Dockerfile | ||
| lang_handler.py | ||
| LICENSE | ||
| log_handler.py | ||
| README.md | ||
| requirements.txt | ||
| screenshot_generator.py | ||
| user_handler.py | ||
| watchdog_script.py | ||
soundbot
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
Screenshots:
Webui:
| Theme | EN Light | EN Dark | DE Light | DE Dark |
|---|---|---|---|---|
| Beige | ![]() |
![]() |
![]() |
![]() |
| Blue | ![]() |
![]() |
![]() |
![]() |
| Cyan | ![]() |
![]() |
![]() |
![]() |
| Default | ![]() |
![]() |
![]() |
![]() |
| Green | ![]() |
![]() |
![]() |
![]() |
| Grey | ![]() |
![]() |
![]() |
![]() |
| Jannik | ![]() |
![]() |
![]() |
![]() |
| Orange | ![]() |
![]() |
![]() |
![]() |
| Pink | ![]() |
![]() |
![]() |
![]() |
| Purple | ![]() |
![]() |
![]() |
![]() |
| Red | ![]() |
![]() |
![]() |
![]() |
| Ugly | ![]() |
![]() |
![]() |
![]() |
| Yellow | ![]() |
![]() |
![]() |
![]() |
Install:
$ git clone https://git.bengt.io/soundbot/soundbot_old
$ 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" ⚠️ Only tested with Adminitstator permissions ⚠️) now copy your url at the bottom and copy it into a new tab and add the bot to your server.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
API Documentation
Authentifizierung
All API-Endpoints are password protected and require a HTTP Basic Auth header.
API Endpoints
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())
Current Features:
Discord Bot Commands
!play <sound_name>
Plays the specified sound in the current voice channel.
!stop
Stops the currently playing sound.
!join <channel_id> (Optional)
Joins the specified voice channel or the channel where the user is currently in.
!leave
Leaves the voice channel the bot is connected to.
!list
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
GET /api/sounds
Returns a list of all registered sound files.
POST /api/sounds/add
Adds a new sound file to the registry.
Request Body:
json
{
"name": "sound_name",
"path": "path/to/sound/file"
}
POST /api/sounds/remove
Removes a sound file from the registry.
Request Body:
json
{
"name": "sound_name"
}
POST /api/sounds/rename
Renames an existing sound file in the registry.
Request Body:
json
{
"oldName": "old_sound_name",
"newName": "new_sound_name"
}
POST /api/sounds/play
Plays a registered sound in the specified Discord channel.
Request Body:
json
{
"name": "sound_name"
}
POST /api/channel/join
Joins a specified voice channel in a Discord server.
Request Body:
json
{
"guild_id": "your_guild_id",
"channel_id": "your_channel_id"
}
POST /api/channel/leave
Leaves the voice channel in the specified Discord server.
Request Body:
json
{
"guild_id": "your_guild_id"
}
POST /api/sounds/stop
Stops the currently playing sound in the specified Discord server.
Request Body:
json
{
"guild_id": "your_guild_id"
}

















































