【发布时间】:2022-01-25 19:53:12
【问题描述】:
我正在尝试确定评论或帖子的所有者是否是它所在的特定 subreddit 的 mod(一般不是版主)。目前我正在使用代码:
if comment.author in self.mods:
这似乎运行,但我不知道它是否真的在做这项工作,或者我是否在这里浪费时间。有人可以确认我做对了吗,或者提出更好的方法?
【问题讨论】:
我正在尝试确定评论或帖子的所有者是否是它所在的特定 subreddit 的 mod(一般不是版主)。目前我正在使用代码:
if comment.author in self.mods:
这似乎运行,但我不知道它是否真的在做这项工作,或者我是否在这里浪费时间。有人可以确认我做对了吗,或者提出更好的方法?
【问题讨论】:
不确定 self.mods 是什么,但如果作者是版主,这将返回子版块的版主列表。 Source
# subreddit would be a string of the subreddit you wish to look at
def listMods(reddit, subreddit):
return [str(moderator) for moderator in reddit.subreddit(subreddit).moderator()]
然后检查作者是否是版主可能看起来像:
mods = listMods(reddit, "dataisbeautiful")
if comment.author in mods:
# do what you need to after checking
reddit 是您的 praw 实例登录到您的帐户
【讨论】: