2017-10-09 79 views
1

我已經使用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

回答

0

感謝您的回答,但原因是在參數*。它應該始終在最後一個參數前1。

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

會工作。