Discord.py "ctx is a required argument that is missing."

864 Views Asked by At

I want my bot to reply with hi to |hello

import discord
from discord.ext import commands
from discord import Game

bot = commands.Bot(command_prefix = "|")
bot.remove_command('help')

#just some console feedback thing, this works fine, dont think it matters here
@bot.event 
async def on_ready():
    await bot.change_presence(game=Game(name="The Gaming"))
    print('All systems online!')
    print('Bot name: '+ bot.user.name)
    servers = list(bot.servers)
    print("Connected to " + str(len(bot.servers)) + " servers")
    for x in range(len(servers)):
        print(' - ' + servers[x-1].name)

#the thing that actually refuses to work
@bot.command()
async def hello(ctx):
    await ctx.send('hi')

bot.run('████████████████████████████████████████████')

Instead of replying with hi to |hello, the bot displays the following error message in the console when |hello is sent:

Ignoring exception in command hello
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 367, in invoke
    yield from self.prepare(ctx)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 345, in prepare
    yield from self._parse_arguments(ctx)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 304, in _parse_arguments
    transformed = yield from self.transform(ctx, param)
  File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 212, in transform
    raise MissingRequiredArgument('{0.name} is a required argument that is missing.'.format(param))
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.

I have checked all dependencies, everything seems to be installed, hell this exact code worked flawlessly about a month ago.

I saw multiple other questions about this error, but all of them were using more complicated code that I'm just not experienced enough to understand.

How could I make it actually do it's thing?

1

There are 1 best solutions below

2
TurboFuture On

There's nothing wrong with the command. Also, bot.servers doesnt exist, its bot.guilds.


@bot.event 
async def on_ready():
    await bot.change_presence(activity=discord.Game(name="The Gaming"))
    print('All systems online!')
    print('Bot name: '+ bot.user.name)
    servers = list(bot.guilds)
    print("Connected to " + str(len(bot.guilds)) + " servers")
    for x in range(len(servers)):
        print(' - ' + servers[x-1].name)

#There's nothing wrong with this command
@bot.command()
async def hello(ctx):
    await ctx.send('hi')

I didnt find any errors with the hello command. Im guessing that you are using an old version of discord.py . So you should switch to discord.py rewrite