Extension 'cogs.reddit' raised an error: TypeError: __init__() missing 1 required positional argument: 'client', how do i fix this?
Extension 'cogs.reddit' raised an error: TypeError: __init__() missing 1 required positional argument: 'client', how do i fix this?
所以,我制作了一个 reddit.py 齿轮,看起来它可以很好地工作(至少对我来说是这样)但是不,我在加载齿轮时遇到异常:“扩展 'cogs.reddit' 引发错误:TypeError: init() missing 1 required positional argument: 'client'"
现在,这是我的代码:
import discord, praw, random
from discord.ext import commands
reddit = praw.Reddit(client_id = '<id>', client_secret = '<secret>', username = '<username>', password = '<password>', user_agent = 'pythonpraw') # this is undoubtedly all correct
# There is an underscore in this class identifier because a "Reddit" class already exists within the "praw" package
class _Reddit(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def meme(self, ctx):
subreddit = reddit.subreddit('memes')
top = subreddit.top(limit=50)
all_submissions = []
for submission in top:
all_submissions.append(submission)
random_submission = random.choice(all_submissions)
submission_name = random_submission.title
submission_url = random_submission.url
embed = discord.Embed(title=submission_name)
embed.set_image(url=submission_url)
await ctx.send(embed=embed)
def setup(client):
client.add_cog(_Reddit())
(我正在使用 discord.py 重写和 Python 3.8.6)
问题出在设置部分。
def setup(client):
client.add_cog(_Reddit(client))
所以,我制作了一个 reddit.py 齿轮,看起来它可以很好地工作(至少对我来说是这样)但是不,我在加载齿轮时遇到异常:“扩展 'cogs.reddit' 引发错误:TypeError: init() missing 1 required positional argument: 'client'"
现在,这是我的代码:
import discord, praw, random
from discord.ext import commands
reddit = praw.Reddit(client_id = '<id>', client_secret = '<secret>', username = '<username>', password = '<password>', user_agent = 'pythonpraw') # this is undoubtedly all correct
# There is an underscore in this class identifier because a "Reddit" class already exists within the "praw" package
class _Reddit(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def meme(self, ctx):
subreddit = reddit.subreddit('memes')
top = subreddit.top(limit=50)
all_submissions = []
for submission in top:
all_submissions.append(submission)
random_submission = random.choice(all_submissions)
submission_name = random_submission.title
submission_url = random_submission.url
embed = discord.Embed(title=submission_name)
embed.set_image(url=submission_url)
await ctx.send(embed=embed)
def setup(client):
client.add_cog(_Reddit())
(我正在使用 discord.py 重写和 Python 3.8.6)
问题出在设置部分。
def setup(client):
client.add_cog(_Reddit(client))