I am trying to grab the score of a inputted URL using a discord bot. 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.
Not sure if this is possible with praw
if it is, someone please correct me. However this is how you can do it using the requests
module. You can get the user's input in discord.py
using 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.