Reputation: 157
I am trying to make my discord.py
bot respond automatically when someone sends some word, but the problem is that the command only works if the word is the first thing to be written in the sentence. I want my bot to respond the message even when the word is in the middle of some sentence. If this is possible, how can I do it?
Upvotes: 4
Views: 56489
Reputation: 1107
The following example will do what you want.
Bot = commands.Bot(command_prefix="")
@Bot.event
async def on_message(message):
if "not" in message.content:
await Bot.send_message(message.channel, 'yes')
To clarify, message.content.startswith
will only check to see if the defined characters/string are at the start of the message, while message.content
scans the entire message sent.
Upvotes: 5
Reputation:
This code snippet should solve the problem.
main.py
:
import discord
client = discord.Client()
@client.event
async def on_message():
if message.content.startswith(‘Exemple’):
message.channel.send(‘this is an exemple’)
client.run(os.getenv(‘TOKEN’))
.env
:
TOKEN=[paste the bot token here]
Upvotes: 0