【问题标题】:Discord.py - Making a command only available in a specific channelDiscord.py - 使命令仅在特定通道中可用
【发布时间】:2021-08-10 06:37:54
【问题描述】:

我一直在尝试设法让该命令仅在特定通道中工作,但似乎没有任何工作。我是 discord.py 的新手,所以我不太了解。

 @client.command(case_sensitive=True)
    async def resus(ctx,*, saymsg=None):
        if saymsg==None:
            return await ctx.send("To reserve a username type - !resus (your discord tag) (the username you want) (if you want verification)!")
    
    
        sayEmbed = discord.Embed(title=f"{ctx.author.name} Said", color = discord.Color.blue(), description=f"{saymsg}")
        sayEmbed.timestamp = ctx.message.created_at
        channelf = client.get_channel(873564203535958047)
        await channelf.send(embed = sayEmbed)

【问题讨论】:

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


    【解决方案1】:

    你可以使用checks

    检查是一个基本谓词,可以将上下文作为其唯一参数。在其中,您有以下选择:

    • 返回 True 表示该人 can run 执行命令。
    • 返回 False 表示该人 cannot run 是命令。
    • 引发 CommandError 派生异常以指示人员无法运行该命令。 这允许您在错误处理程序中处理自定义错误消息。
    async def is_channel(ctx):
        return ctx.channel.id == 123456789
    
    
    @client.command(case_sensitive=True)
    @commands.check(is_channel)
        async def resus(ctx,*, saymsg=None):
    

    【讨论】:

      猜你喜欢
      • 2021-07-02
      • 2021-09-01
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2020-06-15
      相关资源
      最近更新 更多