i have a problem that i can't solve. I'm trying to add a prefix switcher for all guilds, that uses my bot. So I've done that, but currently no command get's triggered and I can't find a solution since hours. Its really frustrating.
import os
import json
import discord.ext
from discord.ext import commands#from discord_slash import SlashCommand, SlashContext
#from discord_slash.utils.manage_commands import create_option, create_choice# Prefix-Wechsler
def get_prefix(client, message):with open("prefix.json", "r") as f:prefix = json.load(f)return prefix(str(message.guild.id))##### Wichtige Bot-Einstellungen ######
intents = discord.Intents().default()
intents.members = Truebot = commands.Bot(command_prefix=str(get_prefix), intents=intents)
bot.remove_command('help')# slash = SlashCommand(bot, override_type = True, sync_on_cog_reload=True, sync_commands=True)### Server-Join ###
@bot.event
async def on_guild_join(guild):with open("prefix.json", "r") as f:prefix = json.load(f)prefix[str(guild.id)] = "="with open("prefix.json", "w") as f:json.dump(prefix, f)### Aktionen für den Bot-Start ###
@bot.event
async def on_ready():print(' ____ _ _ _ _ _ _ _ ')print(' | _ \| | || | | | | (_) | | ')print(' | |_) | | || |_ ___| | _| |_ ___| |_ ')print(' | _ <| |__ _/ __| |/ / | / __| __|')print(' | |_) | | | || (__| <| | \__ \ |_ ')print(' |____/|_| |_| \___|_|\_\_|_|___/\__|')print(' ')print(f'Entwickelt von Yannic | {bot.user.name}')print('────────────')# Prefix-Wechsler
@bot.command(aliases=["changeprefix", "Setprefix", "Changeprefix"])
@commands.has_permissions(administrator=True)
@commands.bot_has_permissions(read_messages=True, read_message_history=True, send_messages=True, attach_files=True, embed_links=True)
async def setprefix(ctx, prefix):if prefix is None:return await ctx.reply('› `📛` - **Prefix vergessen**: Du hast vergessen, einen neuen Prefix anzugeben! <a:pepe_delete:725444707781574737>')with open("prefix.json", "r") as f:prefixes = json.load(f)prefixes[str(ctx.guild.id)] = prefixwith open("prefix.json", "w") as f:json.dump(prefixes, f)await ctx.reply(f'› Mein Bot-Prefix wurde erfolgreich auf `{prefix}` geändert! <a:WISCHEN_2:860466698566107149>')def load_all():for filename in os.listdir('./cogs'):if filename.endswith('.py'):bot.load_extension(f'cogs.{filename[:-3]}')load_all()bot.run("TOKEN")
And that's my task for checking if all bot guilds are in the prefix file (in another cog):
@tasks.loop(minutes=10)
async def prefix_check(self): await self.client.wait_until_ready()
for guild in self.client.guilds:with open("prefix.json", "r") as f:prefix = json.load(f)if guild.id not in prefix:prefix[str(guild.id)] = "="with open("prefix.json", "w") as f:json.dump(prefix, f)