Am receiving an error when trying to run a command saying 'ctx is a required argument that is missing'. [Python, discord.py]

Viewed 128

Hi I am getting this error when I try to run a command:

Ignoring exception in command greet discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing

And when I try to manually pass the context with pass_context=True (I know this is outdated I think)It comes up with: AttributeError: 'Context' object has no attribute 'send'

I have looked everywhere on various forums and I have found others with the same problem but the answers were always specific to that one user's issue and so were useless to me or were outdated, not using the rewrite. I would really appreciate it if someone could help.

Does anyone know why I am getting this and how I could fix it?

Here is what I think is the useful part of the code:

    @client.command()
    async def greet(ctx):
        await ctx.send("Hello")
   

Here is the full code: https://pastebin.com/fQc4vE7F

Edit: I am on discord version 1.4.1 in case that might be useful

2 Answers

The problem seemed to be my IDE. I ran my code in repl and it worked perfectly. Repl automatically installed all the modules. So the issue I think is likely to have been either my installations and imports running on pycharm conflicting with eachother or my pycharm version being outdated since I had not updated it in quite some time. PyCharm had been telling me that the version which I was on being outdated had some bugs with pip...

Anyway, in case anyone else has a similar issue I would recommend to try run your code in repl or some other IDE as the issue in this case was not my code but rather the setup. If you are encountering the same issue on a different IDE I would recommend repl as you do not have to install anything to your computer. Repl is entirely on the cloud and will only install and import what is necessary. And you should probably update the IDE which you already have. I hope I could help anyone else with a similar issue as I could find no solutions online, but I hope I could change this.

you should try re-installing discord.py, also make sure to put the following at the top:

from discord.ext import commands
import discord
Related