评论提交者的用户名

评论提交者的用户名

本文介绍了PRAW:评论提交者的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个reddit机器人,该机器人需要知道哪个用户提交了评论.

I'm developing a reddit bot that needs to know which user submitted a comment.

根据PRAW API包装器文档,没有特定的方法来获取Comment对象作者的用户名.理想情况下,我可以直接找回用户名.如果不可能,是否可以获取作者的全名,然后将其转换为用户名?

According to the PRAW API wrapper docs, there's no specific way to get the username of a Comment object's author. Ideally I could directly get the username back. If that's not possible, is there a way to get the fullname of the author and then convert it to a username?

推荐答案

我是PRAW的维护者.它在哪里说您无法获取Comment对象作者的用户名?因为那是不正确的,需要修复.

I'm a maintainer for PRAW. Where does it say that you cannot get the username of a Comment objects author? Because that is incorrect and needs to be fixed.

无论如何,Comment具有author属性,这是作者的Redditor实例.

Anyway, a Comment has a author attribute, which is a Redditor instance of the author.

import praw

r = praw.Reddit(UNIQUE_AND_DESCRIPTIVE_USERAGENT)
submission = r.get_submission("http://www.reddit.com/r/redditdev/comments/16m0uu/praw_20_is_coming_release_in_2_days/")
comment = submission.comments[0]
author = comment.author  # This returns a ``Redditor`` object.
print(author.name)  # The username

这篇关于PRAW:评论提交者的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:28