当没有 arg 时,如何让它说机器人说些什么

时间:2021-05-12 14:35:58

标签: discord.py

所以我想要的是即使没有 arg 机器人也能做出响应。

到目前为止我所拥有的:

@bot.command()
async def commands(ctx, command_number):
    if int(command_number) == 1:
        embed=discord.Embed(title="**__Commands 1:__**", description="Here the Moderation and Regular commands of this bot, the requirements to use them and their nicknames.\n", color=discord.Color.red())

        embed.add_field(name="**Moderation Commands**", value="`+lock`: Prevents all non-admins from speaking in the channel.\n**Permissions Required**: Role With Manage Channel Permissions\n\n`+unlock`: Allows all non-admins to talk in the channel again.\n**Permissions Required**: Role With Manage Channel Permissions\n\n`+kick`: Kicks the person that you ping after the command `+kick`.\n**Permissions Required**: Role with kick members permissions required.\n\n`+ban`: Bans the person that you ping after the command `+kick`.\n**Permissions Required**: Role with ban members permissions required.\n\n`+blind`: Prevents all non-admins from seeing the channel.\n**Permissions Required**: Role With Manage Channel Permissions.\n\n`+unblind`: Allows all non-admins to talk in the channel again. \n**Permissions Required**: Role With Manage Channel Permissions.", inline=False)

        embed.add_field(name='**Regular Commands**', value='`+announcement`: Sends an announcement to the announcement channel.\n**Permissions Required**: Role With Kick Abilities\n**Nicknames**: `+ann`\n\n`+members`: Shows how many people and bots are on the server and their stats.\n**Nicknames**: `+m`\n\n**The permissions requirements assumes that your admins and moderators are trusted people.*', inline=False)
    
        await ctx.send(embed=embed)

    elif int(command_number) == 2:
        embed=discord.Embed(title="**__Commands 2:__**", description="Here the fun commands of this bot, the requirements to use them and their nicknames.\n", color=discord.Color.red())

        embed.add_field(name='**Fun Commands**', value='`+spam`: Sends a spam message.\n**Permissions Required**: Role With Kick Abilities\n\n`+say`: Makes the bot say the words you said after `+say`.\n**Nicknames**: `+s`\n\n`+bold`: Makes the bot say the words you said after `+bold` in bold.\n**Nicknames**: `+b`\n\n`+italic`: Makes the bot say the words you said after `+italic` in italics.\n**Nicknames**: `+i`\n\n`+strikethrough`: Makes the bot say the words you said after `+strikethrough` crossed out.\n**Nicknames**: `+st`\n\n`+underline`: Makes the bot say the words you said after `+underline` underlined.\n**Nicknames**: `+ul`\n\n`+boldunderline`: Makes the bot say the words you said after `boldunderline` bolded and underlined.\n**Nicknames**: `+bul`\n\n`+bully`: The bot bullies the person you __ping__ after the command `+bully`.\n\n**The permissions requirements assumes that your admins and moderators are trusted people.*', inline=False)

        await ctx.send(embed=embed)

    elif int(command_number) != 1 or 2:
        await ctx.send('That is not a valid page number.')

我试过elif int(command_number) == None: await ctx.send('Please choose a page number')

但是没有用。请帮忙。

1 个答案:

答案 0 :(得分:1)

“它不起作用”,因为您尚未分配默认值 None

@bot.command()
async def commands(ctx, command_number=None):
    if command_number is None:
        return await ctx.send('Please choose a page number')