python - 我将如何检测用户活动?| 不和谐.py
问题描述
我正在尝试制作一个机器人,当输入命令时它会检测用户活动。我写了一些代码,但我得到的机器人的响应不是我想要的。那是我的代码:
from discord import Member
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command()
async def status(ctx):
await ctx.send(Member.activities)
bot.run('token')
这就是我得到的回应:
<“成员”对象的成员“活动”>
我怎样才能解决这个问题?有人会帮助我吗?
解决方案
看来您是 python 新手。Python 是一种面向对象的编程语言,这意味着您需要区分类和实例。
在您的情况下,您正在获取类属性,尽管您需要实例属性。
你想做什么:
@bot.command
async def status(ctx):
await ctx.send(ctx.author.activities)
不过,这会发送一个 python 格式的列表,所以这仍然不是你想要的。
我猜你想做什么:
@bot.command
async def status(ctx):
await ctx.send(ctx.author.activities[0].name)
请注意,您需要更多代码,因为如果成员没有任何活动,这样的命令会引发错误。
推荐阅读
- delphi - 如何在 fmx delphi 中为 utf8 语言(如波斯语)模拟键盘事件?
- javascript - 通过 html datalist 和 *ngFor 显示一个值并提交另一个值
- google-apps-script - 如何将 onEdit 限制为特定单元格中的更改?
- android - 如何使用 FilePcker.Builder 的相机选项隐藏我正在拍摄的画廊中的图像?
- kubernetes - glusterfs heketi 使用分区而不是原始设备以允许轻松扩展
- php - 发送多封电子邮件时出错,应该只发送一封
- rest - 如果休息端点正在使用外部休息端点,Swagger/其他 API 文档/工具能否提供信息
- c# - HTTP 错误 403.14 - 禁止,本地主机:12401
- python - Python exec() 无法在函数中初始化类实例
- sql - sql server 数据透视表查询