【问题标题】:Discord.py API Bot: 2 arguments in function not workingDiscord.py API Bot:函数中的 2 个参数不起作用
【发布时间】:2018-03-20 20:31:33
【问题描述】:

我使用 discord.py API 为我的 Discord 机器人编写了一个名为 spam 的函数,该函数应接受 msg 和 amount 的参数。

msg 只是一个字符串,而 amount 是一个整数(发送 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 个参数的帮助将不胜感激

【问题讨论】:

  • 你在不和谐中输入了什么信息来调用机器人?

标签: python discord


【解决方案1】:

感谢您的回答,但原因是参数中的 *。它应该总是在最后一个参数之前出现 1。

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

会工作的。

【讨论】:

    猜你喜欢
    • 2020-08-16
    • 2019-07-23
    • 1970-01-01
    • 2022-01-17
    • 2017-04-05
    • 2023-03-29
    • 2020-10-13
    • 2021-10-22
    • 1970-01-01
    相关资源
    最近更新 更多