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.
Answers:
As explained in the comments, if you want to compare equality between strings, then:
if message.content == 'sa':
If the message argument is a string the answer by @TerryA works, otherwise you’ll need to read the proper documentation.
@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.
As explained in the comments, if you want to compare equality between strings, then:
if message.content == 'sa':
If the message argument is a string the answer by @TerryA works, otherwise you’ll need to read the proper documentation.