python-3.x - 我如何从作者那里获取文本作为在他们执行命令时触发某些响应的一种方式?
问题描述
假设我做了一个用户用来触发短信的命令。
@client.command()
async def hello(ctx) :
await ctx.send (f'Hey there {ctx.author.name}! Say 1 to access the moderation module and 2 to access the fun module')
如果他们输入 1,我会引导他们进行一系列与输入 2 时不同的动作。
解决方案
您可以在函数中添加一个变量来获取一个值。
打破以下代码:
async def hello(ctx,input:int = None):
输入是一个变量。
:int用于指定您想要的值。它可以是:str :int或空白。
= None用于保持值 None 直到用户输入值。
@client.command()
async def hello(ctx,input:int = None):
if input == None:
await ctx.send (f'Hey there {ctx.author.name}! Say 1 to access the moderation module and 2 to access the fun module')
elif input == 1:
#ACCESS THE MODERATION MODULE
pass
elif input == 2:
#ACCCESS THE FUN MODULE
pass
推荐阅读
- android - 如何防止在recyclerView中解析相同的日期编号
- python - pandas DataFrame: replace values in multiple columns with the value from another
- css - 在现有应用程序中添加延迟加载后,样式不起作用
- c - How can I fill a variable Char from right to left?
- java - JAX-WS 和 SWA 附件
- python - How do I use Pandas to convert an Excel file to a nested JSON?
- r - 如何在 tibble 列中找到最长的重复序列(后续问题)?
- api - 在 Postman 中使用 API 更新对话流中的实体
- c++ - 方法名称和不同类的名称之间的静默名称冲突?
- c# - 如何在 .NET Core 2 程序上使用特定于操作系统的程序?