McTigga
McTigga

Reputation: 11

Discord .py Bot message.content

Probably a pretty easy one but Im coding a discord bot

if message.content.startswith('...'):
    await message.channel.send('...')

Currently, it works if someone's first word is ... (hence the .startswith) is there another attribute to scan the chat for keywords in the middle/end/beginning of the sentence?

Upvotes: 0

Views: 806

Answers (1)

thegigabyte
thegigabyte

Reputation: 131

If you want to look for occurrences of a substring in a string,

in the beginning, use: "string".startswith("substring")

in the middle, use: "substring" in "string"

in the end, use: "string".endswith("substring")

anywhere in the string, use: "substring" in "string"


These expressions will return True if was able to find the substring, and False if not.

So to answer your question directly, the following snippet should solve your problem

if "substring" in message.content:
   # write code here

Upvotes: 1

Related Questions