-1

I am making an STFU bot to make people shut up about when did I ask and stuff and I'm wondering how I would make it so my bot will ignore white space when someone sends the keyword. Here is my code:

@client.event
async def on_message(message):
  if (message.author.bot):
    return
  if 'did i ask' in message.content.lower():
        await message.channel.send('{} Shut up, the world doesnt revolve around you.'.format(message.author.mention))
  if 'who asked' in message.content.lower():
    await message.channel.send('{} Shut up, the world doesnt revolve around you.'.format(message.author.mention))
  if 'stfu' in message.content.lower():
    await message.channel.send('Was I summoned?')
Aditya Tomar
  • 1,601
  • 2
  • 6
  • 25
Novinity
  • 5
  • 4
  • Does this answer your question? [Remove all whitespace in a string](https://stackoverflow.com/questions/8270092/remove-all-whitespace-in-a-string) – CrazyChucky Sep 07 '21 at 23:59
  • Do you need to ignore extra whitespace between character stop? "did I ask" for example? – joshmeranda Sep 08 '21 at 00:02
  • I want to make it so that if someone adds extra space in between each word, it will still detect it – Novinity Sep 08 '21 at 00:20

1 Answers1

0

You can strip the string of all its spaces and compare it to a string with no spaces either:

@client.event
async def on_message(message):
  if (message.author.bot):
    return
  if 'didiask' in (message.content.lower()).replace(" ", ""):
        await message.channel.send('{} Shut up, the world doesnt revolve around you.'.format(message.author.mention))
  if 'whoasked' in (message.content.lower()).replace(" ", ""):
    await message.channel.send('{} Shut up, the world doesnt revolve around you.'.format(message.author.mention))
  if 'stfu' in message.content.lower():
    await message.channel.send('Was I summoned?')
Aditya Tomar
  • 1,601
  • 2
  • 6
  • 25