Answer the question
In order to leave comments, you need to log in
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
Two main problems:
guild
is not defined. In this case, you most likely want to get it from the context - ctx.guildGuild.voice_channels
and 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} права доступа во всех текстовых/голосовых каналах"
)
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 questionAsk a Question
731 491 924 answers to any question