M
M
multiapi2020-08-24 22:57:25
Python
multiapi, 2020-08-24 22:57:25

Issuing access rights?

Good night.
I tried to make a code so that when this role was mentioned, the specified rights were given to it, but I don’t understand how to do it.
My code that turned out

@client.command()
async def set_permissions(сtx, role: discord.Role = None):
  allvoice = guild.voice_channels
  alltext = guild.text_channels
  await alltext.set_permissions(role, read_messages = True, send_messages = True, manage_channels = True, manage_roles = True)
  await allvoice.set_permissions(role, connect = True, manage_channels = True, manage_roles = True)
  await ctx.send(f'{ctx.author.mention}, вы успешно установили {role.mention} права доступа во всех текстовых/голосовых каналах')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-08-25
@multiapi

Two main problems:

  1. The variable guildis not defined. In this case, you most likely want to get it from the context - ctx.guild
  2. Guild.voice_channelsand Guild.text_channels- "lists" with channels of the corresponding type. Lists do not have a set_permissions. The channels in the list have this attribute. To set the rights for each channel, you need to iterate this list.

@client.command()
async def set_permissions(сtx, role: discord.Role):
    for textchannel in ctx.guild.text_channels:
        await alltext.set_permissions(
            role,
            read_messages=True,
            send_messages=True,
            manage_channels=True,
            manage_roles=True,
        )
    for voicechannel in ctx.guild.voice_channels:
        await allvoice.set_permissions(
            role, connect=True, manage_channels=True, manage_roles=True
        )
    await ctx.send(
        f"{ctx.author.mention}, вы успешно установили {role.mention} права доступа во всех текстовых/голосовых каналах"
    )

Z
Zakhar, 2020-08-24
@xzartsust

Well, in your console it says that you can't find guild
Try this:

@client.command()
async def set_permissions(сtx, role: discord.Role = None):
  guild = ctx.message.guild #определяем сервера на котором была использована эта команда
  allvoice = guild.voice_channels
  alltext = guild.text_channels
  await alltext.set_permissions(role, read_messages = True, send_messages = True, manage_channels = True, manage_roles = True)
  await allvoice.set_permissions(role, connect = True, manage_channels = True, manage_roles = True)
  await ctx.send(f'{ctx.author.mention}, вы успешно установили {role.mention} права доступа во всех текстовых/голосовых каналах')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question