【发布时间】:2020-12-24 06:08:32
【问题描述】:
我正在尝试使用不和谐机器人获取输入 URL 的分数。例如,您输入命令,机器人询问 URL,您输入 URL 和不和谐机器人回复的分数。
【问题讨论】:
标签: python bots discord.py praw
我正在尝试使用不和谐机器人获取输入 URL 的分数。例如,您输入命令,机器人询问 URL,您输入 URL 和不和谐机器人回复的分数。
【问题讨论】:
标签: python bots discord.py praw
不确定praw 是否可行,如果可以,请有人纠正我。但是,这是您可以使用 requests 模块的方法。您可以使用Client.wait_for 在discord.py 中获取用户的输入:
@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)
【讨论】: