So I want to make a command where when I say a keyword that has been programmed, the bot can respond to that one word in the sentence like
if message.content.upper().includes(‘keyword’)
So I want to make a command where when I say a keyword that has been programmed, the bot can respond to that one word in the sentence like
if message.content.upper().includes(‘keyword’)
Reminder that you have to be on python3.5.
After installing discord: pip3 install --user discord.py
, and getting the token for your bot:
from discord import Client
bot = Client()
# change keyword here
keyword = "RESPOND"
@bot.event
async def on_message(message):
message_text = message.content.strip().upper()
if keyword in message_text:
# do something here, change to whatever you want
await bot.send_message(message.channel, "'{}' was said".format(keyword))
bot.run("TOKEN")
If you have a bot using commands
, you can initialize it like this instead:
from discord.ext import commands
bot = commands.Bot(command_prefix=commands.when_mentioned)
Note you'll also have to include process_commands
at the end of on_message
.