【问题标题】:Adding member a ticket channel discord.py为会员添加票务频道 discord.py
【发布时间】:2021-04-30 17:43:17
【问题描述】:

我需要票务方面的帮助。当有人想寻求帮助时,一切都很好,创建一个频道和一条消息,但没有将命令的作者添加到票务频道,甚至看不到他。我希望你能帮助我!

   @client.command()
   async def support(ctx, *, reason = None):
      guildid = ctx.guild.id
      guild = ctx.guild
      user = ctx.author
      amount2 = 1
      await ctx.channel.purge(limit=amount2)
      channel = await guild.create_text_channel(f'Ticket {user}')
      await channel.set_permissions(ctx.guild.default_role, send_messages=False, read_messages=False)
      perms = channel.overwrites_for(user)
      await channel.set_permissions(user, view_channel=not perms.view_channel)
      await channel.set_permissions(user, read_message_history=not perms.read_message_history)
      await channel.set_permissions(user, send_messages=not perms.send_messages)
      await channel.send(f"{user.mention}")
      supem = discord.Embed(title=f"{user} Poprosił o pomoc.", description= "", color=0x00ff00)
      supem.add_field(name="Powód", value=f"``{reason}``")
      supem.set_footer(text=f"Wkrótce przyjdzie do ciebie administrator ")
       await channel.send(embed=supem)        

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    你在权限上浪费了很多代码,这要容易得多。
    您可以在这里使用discord.PermissionOverwrite,然后像这样使用它:

    @client.command()
    async def support(ctx, *, reason = None):
        guild = ctx.guild
        user = ctx.author
        await ctx.message.delete() # Deletes the message of the author
        overwrites = {
            guild.default_role: discord.PermissionOverwrite(read_messages=False),
            user: discord.PermissionOverwrite(read_messages=True, send_messages=True)
        }
        channel = await guild.create_text_channel(f'Ticket {user}', overwrites=overwrites)
        await channel.send(f"{user.mention}")
        supem = discord.Embed(title=f"{user} Poprosił o pomoc.", description= "", color=0x00ff00)
        supem.add_field(name="Powód", value=f"``{reason}``")
        supem.set_footer(text=f"Wkrótce przyjdzie do ciebie administrator ")
        await channel.send(embed=supem)
    

    我们做了什么/新代码是如何工作的?

    • guild.default_role: discord.PermissionOverwrite(read_messages=False) 不包括默认角色。
    • user: discord.PermissionOverwrite(read_messages=True, send_messages=True)作者,你定义的用户,拥有对ticket的读写权限。
    • 我们创建了一个新的文本通道,条件为overwrites=overwrites
    • 我删除了guildid = ctx.guild.id,因为您没有在代码中使用它。

    示例 2 在以下网站上也解释得很好:Clik to re-direct

    【讨论】:

      猜你喜欢
      • 2021-06-06
      • 2021-02-27
      • 2021-06-30
      • 2021-09-01
      • 2021-02-08
      • 2021-06-03
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多