Reputation: 237
I'm building a Discord bot on Python and have an issue in code. Here's my entire code:
import discord
from discord import message
from discord.ext import commands
client = commands.Bot(command_prefix='_')
gret_words = ['hi', 'grets', 'greetings', 'mornin', 'hey']
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command(pass_context=True)
async def hello(ctx):
author = ctx.message.author
await ctx.send(f'Hello, {author.mention}! My name is Bot-3P0!')
async def on_message(message):
msg = message.content.lower()
if msg in gret_words:
await message.channel.send("Nice to see you!")
####################
client.run('TOKEN')
But my issue is that, when I type in messenger one word from the gret_words
list, the bot literally doesn't react! I'll be grateful for all help!
Upvotes: 2
Views: 358
Reputation: 950
You need to mark on_message
as an event. Simply add @client.event
on top of async def on_message(message)
and it should work! Edit: you will need to add client.process_commands()
to your on_message()
as well
Upvotes: 3