Discord.py API Bot:函数中的两个参数不起作用

问题描述:

我已经使用discord.py API编写了一个名为spam的函数,该函数使用我的Discord bot,它应该接受msg和amount的参数。Discord.py API Bot:函数中的两个参数不起作用

味精只是一个字符串和数量是一个整数

出于某种原因,我的机器人似乎只在msg参数是捡量不大

(次垃圾邮件msg字符串量)

这是我到目前为止的代码:

@bot.command(pass_context = True) 
async def spam(ctx, *, msg, amount): 
for x in range(0, amount): 
    await bot.say(msg) 

此代码返回错误:

TypeError: spam() missing 1 required keyword-only argument: 'amount' 

任何关于如何有2个参数的帮助将不胜感激

+0

你打电话给机器人的是什么信息? –

+0

错误消息说'amount'是一个*关键字*参数,所以函数应该这样声明:'async def spam(ctx,*,msg,amount = amount)'' – snakecharmerb

感谢您的回答,但原因是在参数*。它应该始终在最后一个参数前1。

@bot.command(pass_context = True) 
async def spam(ctx, msg, *, amount): 
for x in range(0, amount): 
await bot.say(msg) 

会工作。