【问题标题】:How would I detect user status? || Discord.py我将如何检测用户状态? ||不和谐.py
【发布时间】:2018-12-16 22:29:45
【问题描述】:

所以我正在尝试制作一个输入命令时的机器人。它检测用户的在线状态。我还没有开始编写代码,因为我真的不知道该怎么做。有人愿意帮助我吗?

更多文档。我希望命令执行以下操作;

  1. 接受命令“status”
  2. 检查提到的用户状态
  3. 说出用户的状态。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    使用Member 对象的Member.status 属性。它可以是discord.Status 枚举类型的值,也可以是字符串。

    from discord.ext.commands import Bot
    from discord import Member
    
    bot = Bot('!')
    
    @bot.command(pass_context=True, name='status')
    async def status(ctx, member: Member):
        await bot.say(str(member.status))
    
    bot.run('token')
    

    【讨论】:

    • 感谢!谢了哥们! ?
    • 我可以通过添加将其变成 if 语句吗? if member.status == '在线'?
    • if member.status == discord.Status.online:记得import discord
    【解决方案2】:

    对于任何未来的观众,此代码已过时,这是我的更新版本,当然您可以根据需要进行编辑

    @client.command()
    async def status(ctx, member : discord.Member=None):
      if member is None:
        member = ctx.author
      embed=discord.Embed(title=f"{member.name} your current status is", description= f'{member.activities[0].name}', color=0xcd32a7)
      await ctx.send(embed=embed)
    

    【讨论】:

      猜你喜欢
      • 2022-01-17
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 2021-02-10
      • 1970-01-01
      • 2021-03-26
      • 2019-05-09
      相关资源
      最近更新 更多