python - 如何在 PRAW 中找到 Redditor 的名称?
问题描述
我如何从他发表的评论中找出 PRAW 中的 Redditor 的名字。例如,如果用户使用机器人的关键字评论某些内容,他们将收到 PM。要发送这个,必须获得 redditor 的名字。我尝试使用以下语法,但它不起作用并显示错误消息。
for comment in subreddit.stream.comments():
if keyphrase in comment.body:
plebman = comment.author
reddit.redditor(plebman).message("TEST", "BOT TESTING")
出现此错误消息
plebman = comment.author
^
TabError: inconsistent use of tabs and spaces in indentation
i我在 PRAW 中有什么功能可以这样做吗?
解决方案
更新:我在 PRAW 文档中找到了这个命令,它可以从评论中获取作者的名字。以前的方法也很有效,但它被存储为一种名为“redditor”的未知数据类型。此方法将值存储为字符串,消除了我之前遇到的障碍。
然后
for comment in subreddit.stream.comments():
if keyphrase in comment.body:
plebman = comment.author
reddit.redditor(plebman).message("TEST", "BOT TESTING")
现在(在第 3 行更改)
for comment in subreddit.stream.comments():
if keyphrase in comment.body:
plebman = comment.author.name
reddit.redditor(plebman).message("TEST", "BOT TESTING")
或者总结一下
username = comment.author.name
这样,名称被存储为字符串,可以轻松使用。
推荐阅读
- javascript - 异步函数返回一个承诺数组而不是实际的值数组
- python - 在正则表达式中查找出现数字(5-10)的情况
- json - org.json.JSONObject 将数字转换为指数形式
- intellij-idea - 是否有允许从现有代码创建新的单独文件的 IntelliJ 操作或快捷方式
- sequelize.js - 如何使用流类型正确注释 Sequelize 模型?
- javascript - d3 - 访问我点击的区域后面的数据
- jira - 如何在 Jira 票证中突出显示内联代码/文本?
- javascript - JS在有边距的画布上绘制时使用错误的坐标
- c++ - 有人可以解释速记赋值运算符的实际工作原理吗?
- c# - 如果它们重复并且需要全部输出,如何输出最大的数组元素