PRAW:评论提交者的用户名 [英] PRAW: Comment Submitter's Username

查看:26
本文介绍了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:评论提交者的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆