discord.py - Discord.py - 消息在循环中变为“无类型”对象
问题描述
我正在尝试创建一个带有字典的帮助命令,并为带有循环的字典的每个项目创建一些消息编辑,但是当我使用帮助命令AttributeError: 'NoneType' object has no attribute 'edit'
时,它会在涉及 ping 命令时返回错误,我不明白为什么help_msg
变成'NoneType'对象......
这是代码:
@bot.command(aliases = ['h','aide'])
async def help(ctx):
help_msg = await ctx.send("__**Available commands:**__")
for commande, info in help_list.items():
help_msg = await help_msg.edit(content=str(help_msg.content)+commande+info)
@bot.command(pass_context=True)
async def ping(ctx, message=None):
await ctx.send(f":ping_pong: Pong! `{round(bot.latency*1000)}ms`")
p = bot.command_prefix
help_list = {
f"``` {p}help | Alias: {', '.join(help.aliases)}```" : "Affiche la liste des commandes | ?help <commande>",
f"``` {p}ping | Alias: {', '.join(ping.aliases)}```" : "Affiche le ping du bot en ms | ?ping"
}
解决方案
message.edit
没有返回值,所以help_msg
设置为 none。
我相信如果你只是删除分配它应该工作。
for commande, info in help_list.items():
await help_msg.edit(content=str(help_msg.content)+commande+info)
推荐阅读
- ionic-framework - MinDate 和 MaxDate 不适用于 Ionic 4 中的本机日期选择器
- data-protection - 如何在数据保护器中仅启动 idb 服务。需要运行数据库的autovacuum
- swift - 为什么这条线没有被覆盖?Xcode 代码覆盖率
- nginx - Nginx 轮询负载均衡不如预期
- excel - 是否可以基于锁定的模板添加新工作簿
- javascript - 在酶中为服务调用编写测试 - 反应
- visual-studio - Subversion - 无法提交消息和查看历史记录
- mysql - 将第二高的日期与最新的日期进行比较
- sql - 查询count和distinct
- javascript - React:提交表单时子组件不渲染