Search
 
SCRIPT & CODE EXAMPLE
 

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}` ")
Comment

PREVIOUS NEXT
Code Example
Python :: notebook cell print output to file 
Python :: pandas write image to excel 
Python :: lable on graph in matplotlib 
Python :: f string add 0 before python 
Python :: Python random integer number between min, max 
Python :: loginrequiredmixin django 
Python :: ValueError: cannot convert float NaN to integer 
Python :: python sort algorithm 
Python :: python singleton 
Python :: split path in list of directories 
Python :: remove all na from series 
Python :: multiple figures matplotlib 
Python :: heroku[web.1]: Process exited with status 3 
Python :: python remove one character from a string 
Python :: string upper lower count python 
Python :: python turtle module 
Python :: numpy concatenation array 
Python :: mean along third dimension array python 
Python :: default values python 
Python :: python byte like to string 
Python :: .format python 3 
Python :: intersection python dict 
Python :: create column with values mapped from another column python 
Python :: xarray get number of lat lon 
Python :: print without newline 
Python :: palindrome checker python 
Python :: copy dataframe columns names 
Python :: django update field after save 
Python :: separate words in a text to make a list python 
Python :: fast input python 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =