【发布时间】:2018-12-16 22:29:45
【问题描述】:
所以我正在尝试制作一个输入命令时的机器人。它检测用户的在线状态。我还没有开始编写代码,因为我真的不知道该怎么做。有人愿意帮助我吗?
更多文档。我希望命令执行以下操作;
- 接受命令“status”
- 检查提到的用户状态
- 说出用户的状态。
【问题讨论】:
标签: python discord discord.py
所以我正在尝试制作一个输入命令时的机器人。它检测用户的在线状态。我还没有开始编写代码,因为我真的不知道该怎么做。有人愿意帮助我吗?
更多文档。我希望命令执行以下操作;
【问题讨论】:
标签: python discord discord.py
使用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 member.status == discord.Status.online:记得import discord
对于任何未来的观众,此代码已过时,这是我的更新版本,当然您可以根据需要进行编辑
@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)
【讨论】: