如何在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 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'))
洛洛托斯特

根据 Vajra Budiono 回答下的评论,我认为您的意思是:

@bot.command(aliases=['cmd'])
async def command(ctx, parameter = None):
    if arg == None:
        # the default command
    else:
        # command when you pass parameter

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章