Client.event missing required argument 'coro'

Whenever I try my basic bot code, I always get an error message that says this:


Here’s the code:

import discord

client = discord.Client

@client.event
async def on_message(message):
  if message.content == "hi":
    await message.reply("hi!")

client.run("bot token")

I looked at another code for creating a discord bot and in it the client object is created as follows:

import discord
import asyncio
from discord.ext import commands

botToken = '***'

client = commands.Bot(command_prefix = '.')

Could it have something to do with the error being thrown?

You have to add () to instantiate the Client. Otherwise the coroutine (async function) is passed as the self argument (instead of a Client object) so there’s no coro argument.

client = discord.Client()
3 Likes

I’ve tried that before. It gives me another error message.

What is the error message?

This is the error message:
image

Do this: (lines marked with a <- represent required code)

from discord import Client, Intents # <-

intents = Intents.default() # <-
intents.typing = False # <-
intents.presences = False # <-

client = discord.Client(intents=intents) # <-

...
1 Like

Should I put it above the rest of my code? I get another error message when I do that:
image

Oh right.

You should do client = Client(intents=intents), not client = discord.Client(intents=intents). Sorry for the confusion!

1 Like

I’ll try to put it in. Replit is booting again for some reason.

not above.

your new code should be:

from discord import Client, Intents

intents = Intents.default()
intents.typing = False
intents.presences = False
intents.message_content = True

client = Client(intents=intents)

@client.event
async def on_message(message):
  if message.content == "hi":
    await message.reply("hi!")

client.run("bot token")
2 Likes

It works! Thanks man!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.