为所有人锁定频道 discord.py
Lock Channels For Everyone discord.py
所以我试图制作一个 raidmode 命令,我希望它撤销对所有频道的 send_messages 权限....
但我收到一个错误。任何帮助都适用! :D
@commands.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def raidmode(self, ctx, section):
if section == 'on':
guild = ctx.guild
channels = guild.get_all_channels()
role = discord.utils.get(guild.roles, name="@everyone")
await channels.set_permissions(role, send_messages=False)
mbed = discord.Embed(description="Raid Mode Is Enabled!", color=0xe74c3c)
await ctx.send(embed=mbed)
return
if section == 'off':
guild = ctx.guild
channels = guild.get_all_channels()
role = discord.utils.get(guild.roles, name="@everyone")
await channels.set_permissions(role, send_messages=True)
m1bed = discord.Embed(description="Raid Mode Is Disabled!", color=0xe74c3c)
await ctx.send(embed=m1bed)
return
错误
channels = guild.get_all_channels()
AttributeError: 'Guild' object has no attribute 'get_all_channels'
您将需要 Guild.channels
channels = ctx.guild.channels
everyone_role = guild.roles[0] # strictly get the @everyone role (lowest in hierarchy), in case an owner has a role named @everyone
for channel in channels:
if isinstance(channel, discord.TextChannel): # don't change permissions for voice chat or categories
await channel.set_permissions(role, send_messages=False)
另外,请记住,因为允许权限会覆盖拒绝权限,所以这可能不适用于所有频道。
所以我试图制作一个 raidmode 命令,我希望它撤销对所有频道的 send_messages 权限.... 但我收到一个错误。任何帮助都适用! :D
@commands.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def raidmode(self, ctx, section):
if section == 'on':
guild = ctx.guild
channels = guild.get_all_channels()
role = discord.utils.get(guild.roles, name="@everyone")
await channels.set_permissions(role, send_messages=False)
mbed = discord.Embed(description="Raid Mode Is Enabled!", color=0xe74c3c)
await ctx.send(embed=mbed)
return
if section == 'off':
guild = ctx.guild
channels = guild.get_all_channels()
role = discord.utils.get(guild.roles, name="@everyone")
await channels.set_permissions(role, send_messages=True)
m1bed = discord.Embed(description="Raid Mode Is Disabled!", color=0xe74c3c)
await ctx.send(embed=m1bed)
return
错误
channels = guild.get_all_channels()
AttributeError: 'Guild' object has no attribute 'get_all_channels'
您将需要 Guild.channels
channels = ctx.guild.channels
everyone_role = guild.roles[0] # strictly get the @everyone role (lowest in hierarchy), in case an owner has a role named @everyone
for channel in channels:
if isinstance(channel, discord.TextChannel): # don't change permissions for voice chat or categories
await channel.set_permissions(role, send_messages=False)
另外,请记住,因为允许权限会覆盖拒绝权限,所以这可能不适用于所有频道。