[英]PRAW and Discord.py
I am trying to grab the score of a inputted URL using a discord bot.我正在尝试使用不和谐机器人获取输入 URL 的分数。 For instance you put in the command, the bot asks for the URL, you input the URL and the discord bot reply's with the score.
例如,您输入命令,机器人询问 URL,您输入 URL 和不和谐机器人回复的分数。
Not sure if this is possible with praw
if it is, someone please correct me.不确定这是否可能与
praw
使用,请有人纠正我。 However this is how you can do it using the requests
module.但是,这就是您可以使用
requests
模块执行此操作的方法。 You can get the user's input in discord.py
using Client.wait_for
:你可以得到用户的输入
discord.py
使用Client.wait_for
:
@client.command()
async def reddit(ctx):
await ctx.send('Enter submission url.')
def check(m):
return m.author == ctx.message.author and m.channel == ctx.channel
msg = await client.wait_for('message', check=check)
url = f"{msg.content}.json"
data = requests.get(url, headers={'User-agent': 'my discord bot by v1.0 /u/jwd'}).json()
score = data[0]['data']['children'][0]['data']['ups']
await ctx.send(score)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.