python - 未知数量的参数,所以一个或多个 discord.py
问题描述
@bot.command()
async def hellothere(ctx, *, msg):
await ctx.send(ctx + msg)
当我尝试“hello hi hi hi hi”时它不起作用;我希望它可以打印回“hi hi hi hi”,或者如果我输入了 5 个 hi,它会发回 5 个 hi
解决方案
你可能会遇到这样的错误:
TypeError: unsupported operand type(s) for +: 'commands.context.Context' and 'str'
而不是添加Context
( ctx
) 并msg
简单地发送msg
@bot.command()
async def hellothere(ctx, *, msg):
await ctx.send(msg)
同样正如@yungmaz13 所说,您的缩进不正确,尽管我认为这只是一个复制错误。
推荐阅读
- python - 从 tensorflow.js 中的 csv 数据中删除重复行
- javascript - 使用springmvc框架的jQuery Ajax文件上传返回415
- swift - Swift 自动执行异步
- html - 将网页元素复制或导出为 html 文件......这有可能吗?
- variables - Terraform 默认地图值
- javascript - 使用javascript的登录界面
- session - 在 keycloak 中自定义用户会话数据
- node.js - Docker 构建错误:- npm ERR!超出最大调用堆栈大小
- stripe-payments - 在 webhook 触发器中更改 Stripe 示例电子邮件
- c# - 从网络框架应用程序使用托管标识连接到 Azure 应用程序配置