F
F
flurix2020-07-21 21:01:35
Python
flurix, 2020-07-21 21:01:35

Discord.py is it possible to make a one-time command?

I made a command for the bot that creates the MUTED role so that the !mute command that issues this role is used correctly. Here is the command itself:

@bot.command()
@commands.has_permissions(Administrator= True)
async def start(ctx):
    guild = ctx.guild
    perms = discord.Permissions(send_message=False)
    await guild.create_role(name="MUTED", Permissions=perms)
    await ctx.send(embed = discord.Embed(description = '''Первоначальная настройка бота завершена!
Удачного пользования :)''', color = 0x49FF33))

I would like to know if it is possible to make the command so that it can be used only once on one server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Taruu, 2020-07-21
@flurix

The best option is to simply check if there is such a role by simply checking all the roles on the server:

async def findRoleByName(guild,name:str):
    for role in guild.roles:
        if name.lower() in role.name.lower():
            return role #вернет сам объект роли
    else:
        return None

And if we got a role, then we use it ... If not, then we create it and that's it :*

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question