Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to add custom prefix in discord.py

custom_prefixes = {}

#You'd need to have some sort of persistance here,
#possibly using the json module to save and load
#or a database


default_prefixes = ['&']

async def determine_prefix(bot, message):
    guild = message.guild
    if guild:
        return custom_prefixes.get(guild.id, default_prefixes)
    else:
        return default_prefixes

bot = commands.Bot(command_prefix = determine_prefix)

@bot.command()
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def setprefix(ctx, *, prefixes=""):
    custom_prefixes[ctx.guild.id] = prefixes.split() or default_prefixes
    await ctx.send(f"Prefixes set to `{prefixes}` ")
 
PREVIOUS NEXT
Tagged: #add #custom #prefix
ADD COMMENT
Topic
Name
4+5 =