message.content.startswith Discord.Py

Question:

@client.event
async def on_message(message):
    await client.process_commands(message)
    if message.content.startswith('sa'):
        await message.channel.send('as')

This is my code. It should say as when I say sa. It works fine but when I write salah or anything that starts with sa, it detects it and responds. It shouldn’t work like that. I read the documentation but couldn’t find anything, I know that it is becuse of .startswith but I can’t find any replacement for it.

Asked By: Emir Sürmen

||

Answers:

As explained in the comments, if you want to compare equality between strings, then:

if message.content == 'sa':
Answered By: TerryA

If the message argument is a string the answer by @TerryA works, otherwise you’ll need to read the proper documentation.

Answered By: 22_prajwol poudel
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.