【问题标题】:How can I "check" if the channel is private?我如何“检查”频道是否为私人频道?
【发布时间】:2019-03-18 06:26:59
【问题描述】:

如何在 discord.py 重写中“检查”频道是否为私有, 我什至看到了一个类似的问题,但答案不起作用:

【问题讨论】:

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


    【解决方案1】:

    检查通道是否是PrivateChannel抽象基类的实例:

    from discord.abc import PrivateChannel
    from discord.ext.commands import Bot    
    
    bot = Bot(command_prefix='!')
    
    @bot.command()
    async def isprivate(ctx):
        await ctx.send(isinstance(ctx.channel, PrivateChannel))
    
    bot.run("token")
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题并像这样解决它。 :)

      @bot.event
      async def on_message(message):
          if str(message.channel.type) == "private":
              print("message is privat...")
          else:
              print("message is not private...") 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-02-19
        • 2021-04-13
        • 2022-12-16
        • 2015-11-27
        • 1970-01-01
        • 2021-12-13
        • 2021-05-23
        • 2019-11-30
        相关资源
        最近更新 更多