F
F
flurixxx2020-07-22 16:33:56
Python
flurixxx, 2020-07-22 16:33:56

Discord.py role auto-assignment + id command, how to do it?

In general, I wanted to implement such a scheme:
in order for the bot to automatically issue a role on the server, the administrator must write !autorole [ID], where ID is the id of the role that the bot issues (when entering the server, to each user). But I don't fully understand how to implement it, can anyone help?
Here is the code itself:

@bot.command()
@has_permissions(administrator=True)
async def autorole(ctx, autoroles: int):
    await ctx.send(embed = discord.Embed(description = f'ID роли для авто-выдачи указано.',color=0xFF8C00))

And then use autoroles as the channel ID, but it didn't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SerjLore, 2020-10-01
@SerjLore

Hello. (If relevant) The
bot executes the command like this:
1. Create a loop with the "bot.guilds" object.
2. Search in the 1st item "member" on the entire server.
3. Search for role ID by name. (Or think for yourself how to do it by ID, I have an error that you can’t issue a role by ID)
4. Issuing a role by action from the 3rd paragraph.
5. Report.
The codes themselves, I use cogi so there are 2 options.
Kogi:

@commands.command() # начало команды
  @commands.has_permissions(administrator = True) # нужны права администратора? - да
  async def ar(self, ctx, autoroles): #сама команда и что ей надо указать, это prefix, комаду и НАЗВАНИЕ роли.
    for guild in self.bot.guilds: # оно ищет на сервере людей
      for member in guild.members: # и тут делается все работа для member-a
        autoroles2 = discord.utils.get(ctx.message.guild.roles, name = autoroles) # нахождение айди по названию, иначе будет ошибка(у меня)
        await member.add_roles(autoroles2) # само добавление роли
    emb = discord.Embed(description = 'Роли успешно добавлены ВСЕМ участникам Discord сервера.')
    await ctx.send(embed = emb) # теперь бот сообщает что всё вышло.

Not Kogi:
@bot.command() # начало команды
@bot.has_permissions(administrator = True) # нужны права администратора? - да
async def ar(ctx, autoroles): #сама команда и что ей надо указать, это prefix, комаду и НАЗВАНИЕ роли.
  for guild in bot.guilds: # оно ищет на сервере людей
    for member in guild.members: # и тут делается все работа для member-a
      autoroles2 = discord.utils.get(ctx.message.guild.roles, name = autoroles) # нахождение айди по названию, иначе будет ошибка(у меня)
      await member.add_roles(autoroles2) # само добавление роли
  emb = discord.Embed(description = 'Роли успешно добавлены ВСЕМ участникам Discord сервера.')
  await ctx.send(embed = emb) # теперь бот сообщает что всё вышло.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question