【问题标题】:Lock Channels For Everyone discord.py为每个人锁定频道 discord.py
【发布时间】:2021-03-24 05:23:55
【问题描述】:

所以我试图创建一个 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'

【问题讨论】:

标签: python python-3.x discord discord.py discord.py-rewrite


【解决方案1】:

你需要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)

另外,请记住,由于允许权限覆盖拒绝权限,这可能不适用于所有渠道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-07
    • 2022-01-24
    • 2018-06-16
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2019-04-08
    • 2021-02-16
    相关资源
    最近更新 更多