Python 如何在discord py中创建默认命令?

Python 如何在discord py中创建默认命令?,python,discord,discord.py,Python,Discord,Discord.py,我希望在同一个命令中有两个命令,一个默认命令是“presencas”,另一个参数是“presencascanal” 以下是我的代码: # Command to know how much people are in general @bot.command(name='presencas') @commands.has_role(admin_id) async def on_message(ctx): await ctx.send('Presenças no servidor no di

我希望在同一个命令中有两个命令,一个默认命令是“presencas”,另一个参数是“presencascanal”

以下是我的代码:

# Command to know how much people are in general
@bot.command(name='presencas')
@commands.has_role(admin_id)
async def on_message(ctx):
    await ctx.send('Presenças no servidor no dia: ' + str(datetime.now().date()) + ' às ' + time.strftime(r"%H:%M") + 'H')
    with open('presencas_' + str(datetime.now().date()) + '.csv', 'w', newline='') as file:

        writer = csv.writer(file, delimiter=':', quoting=csv.QUOTE_NONE)
        writer.writerow(['Nome, tag, timestamp'])

        for user in ctx.guild.members:
            writer = csv.writer(file, delimiter='"', quoting=csv.QUOTE_NONE)
            if user.status != discord.Status.offline:
                writer.writerow([user.name + ', ' + '#'+user.discriminator + ', ' +str(datetime.now().date()) + ' ' + time.strftime(r"%H:%M") + 'H'])

    await ctx.send(file=discord.File(r'presencas_' + str(datetime.now().date()) + '.csv'))


#Command to know how much people are a specific channel
@bot.command()
@commands.has_role(admin_id)
async def presencascanal(ctx, canal):

    channel = bot.get_channel(int(canal))  # Canal de onde a lista vem

    members = channel.members  # Encontra os membros que estão no canal

    await ctx.send('Presenças no canal ' + channel.name + ' no dia ' + str(datetime.now().date()) + ' às ' + time.strftime(r"%H:%M") + 'H')
    with open('presencas_canal_' + channel.name + '_' + str(datetime.now().date()) + '.csv', 'w', newline='') as file:

        writer = csv.writer(file, delimiter=':', quoting=csv.QUOTE_NONE)
        writer.writerow(['Nome, tag, timestamp'])

        for user in members:
            writer = csv.writer(file, delimiter='"', quoting=csv.QUOTE_NONE)
            if user.status != discord.Status.offline:
                writer.writerow([user.name + ', ' + '#'+user.discriminator + ', ' +str(datetime.now().date()) + ' ' + time.strftime(r"%H:%M") + 'H'])

    await ctx.send(file=discord.File(r'presencas_canal_' + channel.name + '_' + str(datetime.now().date()) + '.csv'))

我想你想用不同的命令执行一个命令函数,我希望这是对的,你可以在命令装饰器中传递一个参数,它叫做别名,下面是你传递它的方式:

@bot.command(aliases=['cmd'])
async def command(ctx):
    ctx.channel.send('test')
现在你有了一个名为“command”的默认值,你还可以用“cmd”激活该函数,你还可以在别名列表中添加更多别名

下面是一个输出示例,前缀为“!”:


希望我能帮上忙,如果你想问些什么,就在这个答案下给我一个评论吧

根据金刚武道答案下的评论,我想你的意思是:

@bot.command(别名=['cmd'])
异步定义命令(ctx,参数=无):
如果arg==无:
#默认命令
其他:
#当您传递参数时的命令

parameter=None
意味着如果在默认情况下调用没有参数的命令,此参数将具有
None
值。

您的问题到底是什么?你有什么错误吗?问题是什么?我想把这两个命令放在一起基本上,它们做相同的事情,那么如果我能把它们放在一起,为什么我需要两个呢?我只是不知道怎么做。我搜索了所有内容以查找此信息,但没有任何内容
ctx.send
是一个协同程序,它应该是waitedit的类型,但我希望同一个命令可以执行两个不同的操作。我希望在键入该命令时为该命令创建一个默认函数,我希望创建一个更复杂的函数。例如presencas应该执行默认功能,但当您键入时!现在它应该做另一件事。我不知道我是否足够清楚,但基本上就是这样,你可以使用辅助输入,比如在命令中添加一个额外的命令,比如!命令额外的数据是的,我想是这样的
user: !command
bot: test
user: !cmd
bot: test