首页 > 解决方案 > 未知数量的参数,所以一个或多个 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

标签: pythonpython-3.xdiscord.py

解决方案


你可能会遇到这样的错误:

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 所说,您的缩进不正确,尽管我认为这只是一个复制错误。


推荐阅读