【问题标题】:Discord.py ask for reply from people with specific roleDiscord.py 要求具有特定角色的人回复
【发布时间】:2021-11-01 17:35:44
【问题描述】:
@bot.command(aliases=['writing'])
async def shiritori(ctx):
    def check(msg):
        return msg.author == ctx.author and msg.channel == ctx.channel

    while True:
        msg = await bot.wait_for('message', check=check)
        await ctx.send(str(msg))

此代码等待用户消息输入并将输入消息重新发送到聊天室。但是代码只回复使用“/writing”启动命令的人。如何让代码在任何人启动命令后回复任何具有不和谐角色'@writer'的人?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您应该在check() 函数中更改if 语句并检查消息作者是否具有@writer 角色:

    @bot.command(aliases=['writing'])
    async def shiritori(ctx):
        def check(msg):
            return msg.channel == ctx.channel and '@writer' in [x.name for x in msg.author.roles]
    
        while True:
            msg = await bot.wait_for('message', check=check)
            await ctx.send(str(msg))
    

    【讨论】:

      猜你喜欢
      • 2021-06-29
      • 1970-01-01
      • 2021-10-08
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      相关资源
      最近更新 更多