【发布时间】:2021-07-27 12:40:54
【问题描述】:
我的 Reddit meme 命令不起作用。当我说&meme 时,我希望我的机器人回复一个表情包,但是它没有回复,而是给出了运行时错误:
/usr/lib/python3.8/asyncio/events.py:81: RuntimeWarning: coroutine 'SubredditHelper.__call__' was never awaited
self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
代码是:
@client.command()
async def meme(ctx):
reddit = asyncpraw.Reddit(client_id = "redditclientid", client_secret = "redditsecret", username = "redditusername", password = "redditpassword", user_agent = "chrome")
subreddit = reddit.subreddit("memes")
all_subs = []
top = subreddit.top(limit = 50)
for submission in top:
all_subs.append(submission)
random_sub = random.choice(all_subs)
name = random_sub.title
url = random_sub.url
em = discord.Embed(title = name)
em.add_field(url = url)
await ctx.send(embed = em)
你能帮我找出错误吗?
【问题讨论】:
-
总是将完整的错误消息(从单词“Traceback”开始)作为文本(不是截图,不是链接到外部门户)有问题(不是评论)。还有其他有用的信息。
-
我认为您不需要
for submission in top: all_subs.append(submission),因为它可能只会将值从一个列表复制到另一个列表,如果您在random.choice(top)中使用top而不是all_subs,那么您应该得到结果相同。 -
错误是关于
async和函数asyncpraw的名称有单词async- 所以它可能需要使用await-reddit = await asyncpraw.Reddit(...)或top = await subreddit.top(limit = 50) -
或者你可能需要这个
for-loop 但使用async- 比如asyn for ... in ...: ...
标签: python discord.py