【问题标题】:How to make it say the bot say something when there is no arg没有 arg 时如何让它说机器人说些什么
【发布时间】:2021-08-02 22:36:29
【问题描述】:

所以我想要的是机器人即使没有 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')

但它没有用。请帮忙。

【问题讨论】:

    标签: discord.py


    【解决方案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')
    

    【讨论】:

      猜你喜欢
      • 2021-08-03
      • 1970-01-01
      • 2020-12-01
      • 2021-03-14
      • 2019-08-03
      • 1970-01-01
      • 2021-05-20
      • 1970-01-01
      • 2021-04-27
      相关资源
      最近更新 更多