命令案例Insensitve

时间:2018-05-25 09:21:35

标签: python python-3.x discord discord.py

如果成员在低位或高位使用以下命令或混合,如何使下面的命令工作。 如果成员使用ping则有效。 但如果成员使用Ping则不起作用。

@bot.event
async def on_message(message):
    message.content = message.content.lower()
    await bot.process_commands(message)

    @bot.command(pass_context=True)
    async def ping(ctx):
        msg = 'Pong {0.author.mention}'.format(ctx.message)
        await bot.say(msg)

更新

以上on_message在单个文件中正常工作但我将主文件拆分为多个文件。现在如何使它适用于所有文件中的cog。

1 个答案:

答案 0 :(得分:0)

您可以在创建Bot时将case_insensitive选项传递给from discord.ext import commands bot = commands.Bot('!', case_insensitive=True) @bot.command(pass_context=True) async def ping(ctx): msg = 'Pong {0.author.mention}'.format(ctx.message) await bot.say(msg)

public static void main(String[] args) {
    System.out.println("Quenten's Copy");
    Scanner input = new Scanner(System.in);

    int number[] = new int [1000000]; // initialize first array
    int count[] = new int [1000000]; // initialize second array
    int temp = 0; // intialize integer to hold for comparison
    int i; // intialize loop integer

    System.out.print("Enter seven numbers: "); // ask user for input

    // first loop - takes in user input
    for (i = 0; i < 7; i++) {
        number[i] = input.nextInt();
        }

     // second loop - checks for reoccurance of numbers
    for (i = 0; i < number.length; i++) {
        temp = number [i];
        count [temp]++;
    }

    // final loop - gives the output of the count
    for (i = 1; i < count.length; i++) {
        if (count [i] > 0) {

            // output statement - tells user each number and how many
            // times each number occurs
            System.out.printf("Number %d occurs %d times\n", i, count [i]);



        }
    }