From 212e10d9a74cc17b832bdc78d4150c9226b67b5a Mon Sep 17 00:00:00 2001 From: Uwe Pfeifer Date: Wed, 7 May 2025 09:39:17 +0200 Subject: [PATCH 1/3] Add botprefix config option --- bot.ini.example | 6 +++++- pybot-f.py | 6 ++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bot.ini.example b/bot.ini.example index ebc443f..52c3d2d 100644 --- a/bot.ini.example +++ b/bot.ini.example @@ -11,6 +11,10 @@ # try searching the internet for "How to create a Discord bot token" or # visit: https://discordpy.readthedocs.io/en/latest/discord.html # Also don't forget to invite the bot onto your server(s). +# +# - botprefix +# This is the prefix for commands when not using slash-commands. [General] -bottoken=BOTTOKEN_HERE \ No newline at end of file +bottoken=BOTTOKEN_HERE +botprefix=. diff --git a/pybot-f.py b/pybot-f.py index bee0bf2..ca639c0 100644 --- a/pybot-f.py +++ b/pybot-f.py @@ -11,9 +11,6 @@ from logging import handlers # Logging -#loghandler = logging.FileHandler(filename='bot.log', encoding='utf-8', mode='w') -#discord.utils.setup_logging(handler=loghandler) - logger = logging.getLogger('discord') logger.setLevel(logging.INFO) @@ -48,10 +45,11 @@ config.read('bot.ini') bottoken = config['General']['bottoken'] +botprefix = config['General']['botprefix'] # Setting up commands.Bot -bot = commands.Bot(command_prefix='.', description=description, intents=intents) +bot = commands.Bot(command_prefix=botprefix, description=description, intents=intents) @bot.event From 9b1fd2f315faebeb872c61081f7d168c38a7a47a Mon Sep 17 00:00:00 2001 From: Uwe Pfeifer Date: Wed, 7 May 2025 10:03:58 +0200 Subject: [PATCH 2/3] Added possibility to define multiple prefixes --- pybot-f.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pybot-f.py b/pybot-f.py index ca639c0..c073fe5 100644 --- a/pybot-f.py +++ b/pybot-f.py @@ -45,11 +45,20 @@ config.read('bot.ini') bottoken = config['General']['bottoken'] -botprefix = config['General']['botprefix'] +botprefixes = config['General']['botprefixes'] + + +def get_prefixes(bot, message): + """ + For setting the bots prefixes in addition to mentions. + """ + + prefixes = botprefixes # Can be a list of strings + return commands.when_mentioned_or(*prefixes)(bot, message) # Setting up commands.Bot -bot = commands.Bot(command_prefix=botprefix, description=description, intents=intents) +bot = commands.Bot(command_prefix=get_prefixes, description=description, intents=intents) @bot.event From 4a5f85860ea511a242a6d884b663a21587671a48 Mon Sep 17 00:00:00 2001 From: Uwe Pfeifer Date: Wed, 7 May 2025 10:09:00 +0200 Subject: [PATCH 3/3] It's now possible to set multiple botprefixes --- bot.ini.example | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot.ini.example b/bot.ini.example index 52c3d2d..6913281 100644 --- a/bot.ini.example +++ b/bot.ini.example @@ -12,9 +12,11 @@ # visit: https://discordpy.readthedocs.io/en/latest/discord.html # Also don't forget to invite the bot onto your server(s). # -# - botprefix +# - botprefixes # This is the prefix for commands when not using slash-commands. +# Can also contain several prefixes, define it like: botprefixes=['!', '?','.'] +# (list of strings) [General] bottoken=BOTTOKEN_HERE -botprefix=. +botprefixes=.