首页 > 解决方案 > 我如何从作者那里获取文本作为在他们执行命令时触发某些响应的一种方式?

问题描述

假设我做了一个用户用来触发短信的命令。

@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 时不同的动作。

标签: python-3.xdiscord.pydiscord.py-rewrite

解决方案


您可以在函数中添加一个变量来获取一个值。
打破以下代码:

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

推荐阅读