简体   繁体   中英

How do i make a discord bot not case-sensitive? discord.py

How do i make a discord bot not case sensitive? The method I'm currently using isn't working. I've seen other quest like this but they aren't related to what I'm doing.

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

bot = commands.Bot(command_prefix='', case_insensitive=True) #ive tried both true/false. neither works 

print("Starting...")

@bot.event
async def on_ready():
  print("Logged on as {0.user}".format(bot))

  @bot.event
  async def on_message(message):
    if message.author == bot.user:
      return

    elif 'hello' in message.content:
        await message.delete()
        await message.channel.send(‘hi')
bot.run("Token")

I want the user to be able to say either Hello or hello and it will work. Any ideas on how i would go about that?

I'm fairly new to this myself so the method I know is you can use .lowercase() when comparing. What this will do is it'll convert the whole string to lowercase, it doesn't matter if the user wrote "Hello", "hello" , "HEllO", etc. All these strings would be converted to "hello" when .lowercase() is used.

This is my first answer so hope I was able to explain it properly. Attaching the code for your reference.

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

bot = commands.Bot(command_prefix='', case_insensitive=True) #ive tried both true/false. neither works 

print("Starting...")

@bot.event
async def on_ready():
  print("Logged on as {0.user}".format(bot))

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return

    elif 'hello' in message.content.lower():
        await message.delete()
        await message.channel.send(‘hi')

bot.run("Token")

Let me know if it works!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM