【问题标题】:How would you extend the user input of a discord command to more than just one word?您如何将不和谐命令的用户输入扩展到不止一个单词?
【发布时间】:2021-01-25 09:14:10
【问题描述】:

我正在制作一个 discord.py 命令,该命令将接受用户输入某条消息并重复该消息。到目前为止,这是我的代码:

async def repeat(ctx, words = None):
    if words == None:
        reason = 'you didn\'t say anything dummy'
    await ctx.send(f'{words}')

但是,当我去实际测试命令时,机器人只发回我的消息中的一个字。例如,如果我说“do repeat a b c”,它只会发送“a”。如何让机器人接受我说的所有单词?

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    您可以使用仅限关键字的参数:

    async def repeat(ctx, *, words):
    

    这将自动将所有参数作为单个字符串。

    见:https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html#keyword-only-arguments

    【讨论】:

      猜你喜欢
      • 2018-07-01
      • 1970-01-01
      • 2018-03-17
      • 2021-08-19
      • 2021-04-10
      • 2021-10-05
      • 2018-11-10
      • 2019-04-26
      • 2020-09-25
      相关资源
      最近更新 更多