No description
  • Python 46.6%
  • CSS 33.5%
  • HTML 19.6%
  • Dockerfile 0.3%
Find a file
2025-12-24 00:45:19 +01:00
.vscode mainly tabcompletion for /play (soundbot/soundbot#30) 2024-11-22 20:11:32 +01:00
config fixes 2025-01-18 11:26:43 +01:00
interface Fixed #52 2024-12-11 14:18:42 +01:00
lang implemented #38 2024-12-07 12:54:41 +01:00
screenshots refreshed screenshots 2024-12-20 16:50:58 +01:00
.dockerignore More Logging (soundbot/soundbot#35) 2024-11-29 15:40:18 +01:00
.gitignore Update .gitignore 2025-05-23 09:17:40 +00:00
bot.py fixes 2025-01-18 11:26:43 +01:00
config_handler.py removed old leftover code from fixing soundbot/soundbot#22 2024-11-22 07:42:15 +00:00
Dockerfile better docker 2024-11-23 12:55:06 +01:00
lang_handler.py Added the stuff of my private bot version 2024-11-21 18:07:31 +01:00
LICENSE Initial commit 2024-08-09 09:36:25 +02:00
log_handler.py fixed logs allways showing the same time 2024-12-06 20:41:02 +01:00
README.md New Domain 2025-12-24 00:45:19 +01:00
requirements.txt Update requirements.txt 2024-12-14 19:23:17 +00:00
screenshot_generator.py added #43 2024-12-06 16:12:26 +01:00
user_handler.py fixes 2025-01-18 11:26:43 +01:00
watchdog_script.py Dropdowns (finally) soundbot/soundbot#14 2024-11-29 22:32:41 +01:00

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_id and channel_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_id and channel_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"
}