I have a class in code.py in a folder(cog) that looks like this:
import discord
from discord.ext import commands
class Class(commands.Cog):
def __init__(self):
# Basic initialisation
@commands.command()
async def func(self, ctx = commands.Context):
# Code for the command
When I try to import it (to add it to a scheduler using APScheduler
) like the following:
from folder import code
async def schedule_func():
func_class = code.Class()
await func_class.func()
I get the following error:
File "bot/main.py", line 45, in schedule_meme
await func_class.func()
File "/python/lib/python3.8/site-packages/discord/ext/commands/core.py", line 374, in __call__
return await self.callback(*args, **kwargs)
TypeError: func() missing 1 required positional argument: 'self'
I looked up everywhere and double-checked that I was initialising the class first but still I can't get past the error.
What am I doing wrong here?
Not exactly sure what happened here, it is reproducible and it worked when I simply passed ctx as a random value.
await func_class.func(commands.Context) #if you need to use it, or just 1 or any literal
edit: the commands.command()
decorator seems to be the problem here, removing it made it run without a parameter, my guess is that the decorator made ctx a required argument, if you don't want to use ctx. you can change the decorator to @commands.command(pass_context=False)
and it will run fine without any parameters
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.