EkteFrokostNam
EkteFrokostNam

Reputation: 55

Why isnt my discord bot answering to my messages?

I made this small discord bot to show a friend how to do it, exactly how I have done it before. But it doesnt answer my message in discord, and I cant find the error.

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
  print('Online as {0.user}'.format(client))

@client.event
async def in_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('Hello'):
    await message.channel.send('Hello! {message.author.mention}')

client.run(os.getenv('TOKEN'))

Sorry if its obvious, I just cant see it.

Upvotes: 1

Views: 161

Answers (2)

Nxrmqlly
Nxrmqlly

Reputation: 67

instead of using on_message events u can use

@client.command()
async def hello(ctx):
   await ctx.send(f"Hello {ctx.author.mention}")

This is how u create actual Commands in discord.py

Upvotes: 0

Ratery
Ratery

Reputation: 2917

  1. Use on_message instead of in_message.
  2. Format string 'Hello! {message.author.mention}' like f'Hello! {message.author.mention}'.

Upvotes: 2

Related Questions