【问题标题】:How to have input in a command in discord.py如何在 discord.py 中输入命令
【发布时间】:2021-09-03 16:11:43
【问题描述】:

我正在尝试在命令中获取输入,因此它的命令 + 输入在同一行中。

例如:/cmd 输入

因此,一些变量将等于输入,我将能够访问它并可能对其进行操作。

这是一个代码 sn-p 让你更好地理解我想要坐的东西

import discord
from discord.ext import commands, tasks

client = commands.Bot(command_prefix = '/')

messages = []
@client.command()
async def candidate(ctx, userinput): #this won't work obviously
    messages.append('userinput')

我有办法做到这一点吗?

【问题讨论】:

  • 我不太确定您要做什么。您是否试图让您的机器人发送用户的消息?您能否将您的问题编辑得更清楚一些,以便我们更好地为您提供帮助?
  • 我只是想将它存储在某个变量中以便我可以访问它

标签: python discord command discord.py


【解决方案1】:

您希望您的命令接收一个参数(或更多)然后使用它。它应该类似于以下内容:

@client.command()
async def candidate(ctx, arg): # "arg" will have the first argument the user sent when he used the command "candidate"
    response = "The first argument received was: " + arg
    await ctx.send(response)

所有这些都在文档中进行了解释: https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html?highlight=argument#parameters

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2019-05-09
    • 2021-01-13
    • 2021-06-04
    • 2021-06-01
    • 2021-01-13
    • 2021-03-19
    相关资源
    最近更新 更多