I try to make a auto response bot for something like automated support everytime i type: hey i
The bot outputs this Error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\lequi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'ctx'
But i have did ctx in de function so i dont know whats wrong with the code I hope you guys can help me :D
Please help me if you can :D
@bot.event
async def on_message(message, ctx):
if 'hey' in message.content.lower():
if 'i' in message.content.lower():
embed = discord.Embed(title=f'test',description=f'**test** : ``test``', color=0x001fff )
await ctx.send(embed=embed)
if 'test' in message.content.lower():
embed = discord.Embed(title=f'test',description=f'**test** : ``test``', color=0x001fff )
await ctx.send(embed=embed)```
The on_message
only has 1 input argument (see documentation).
Thus your code:
@bot.event
async def on_message(message, ctx):
if 'hey' in message.content.lower():
if 'i' in message.content.lower():
embed = discord.Embed(title=f'test',description=f'**test** : ``test``', color=0x001fff )
await ctx.send(embed=embed)
if 'test' in message.content.lower():
embed = discord.Embed(title=f'test',description=f'**test** : ``test``', color=0x001fff )
await ctx.send(embed=embed)
Is incorrect as you specify 2 input arguments, instead of 1 (i.e. you are adding a new required positional argument).
So now the question why does it say: TypeError. on_message() missing 1 required positional argument: 'ctx'
?
Well it is very simple, the process that executes the on_message event doesnt have a second input argument for what you call "ctx", as it expected only 1 input argument and not two. Thus throwing this error.
Removing ctx will solve the problem, if not then you have other code that is interfering (something you havent showed). Example of how to do this below.
@bot.event
async def on_message(message):
if 'hey' in message.content.lower():
if 'i' in message.content.lower():
embed = discord.Embed(title=f'test',description=f'**test** : ``test``', color=0x001fff )
await message.channel.send(embed=embed)
if 'test' in message.content.lower():
embed = discord.Embed(title=f'test',description=f'**test** : ``test``', color=0x001fff )
await message.channel.send(embed=embed)