Answer the question
In order to leave comments, you need to log in
Discord.py command disposability?
I wanted to make a !start command that creates the "muted" role on the server, but so that it works 1 time on one server. Here is the code itself:
@bot.command()
@has_permissions(manage_roles=True)
async def start(ctx,name="muted"):
guild = ctx.guild
for role in guild.roles:
if name.lower() not in role.name.lower():
perms = discord.Permissions(send_messages=False)
await guild.create_role(name="muted", permissions=perms)
await ctx.send(embed = discord.Embed(description = '''Первоначальная настройка бота завершена!
Удачного пользования :)''', color = 0x49FF33))
return role
else:
await ctx.send(embed = discord.Embed(description = 'Бот уже настроен!', color = 0x49FF33))
return role
Answer the question
In order to leave comments, you need to log in
there are many ways.
for example, include a .json file.
after using the !start command, write the server ID and number of uses to this file.
create a condition: if the number of uses = 1, the bot sends some message to the chat
You can create a role when you enter the server using the on_guild_join event, and already when you enter the server, the bot will make its own role (you need protection from the limit of roles on the server)
. Also, if there is a database, then simply enter the settings data on this server.
You can also use a decorator to check. Is there a role on the server. (Check against the role name)
An example from the documentation:
async def is_owner(ctx):
return ctx.author.id == 316026178463072268
@bot.command(name='eval')
@commands.check(is_owner)
async def _eval(ctx, *, code):
"""A bad example of an eval command"""
await ctx.send(eval(code))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question