0

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?

Superior125
  • 55
  • 3
  • 9
  • 2
    `elif 'hello' in message.content.lower():` To make a comparison case-sensitive, just force the two strings you're comparing to be lowercase (or uppercase, as long as you use the same case for both strings). – Samwise Jul 28 '21 at 16:20
  • 1
    Where is your `@bot.command` that you want to be case-insensitive? – Barmar Jul 28 '21 at 16:21
  • Does this answer your question? [How do I do a case-insensitive string comparison?](https://stackoverflow.com/questions/319426/how-do-i-do-a-case-insensitive-string-comparison) – Yevhen Kuzmovych Jul 28 '21 at 16:35
  • I’m not using commands I’m just detecting if messages are sent – Superior125 Jul 28 '21 at 16:43
  • Could you write that as an answer so I can accept it? – Superior125 Jul 28 '21 at 17:27

1 Answers1

0

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!!