【问题标题】:PRAW and Discord.pyPRAW 和 Discord.py
【发布时间】:2020-12-24 06:08:32
【问题描述】:

我正在尝试使用不和谐机器人获取输入 URL 的分数。例如,您输入命令,机器人询问 URL,您输入 URL 和不和谐机器人回复的分数。

【问题讨论】:

    标签: python bots discord.py praw


    【解决方案1】:

    不确定praw 是否可行,如果可以,请有人纠正我。但是,这是您可以使用 requests 模块的方法。您可以使用Client.wait_fordiscord.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)
    

    【讨论】:

      猜你喜欢
      • 2020-12-09
      • 2020-09-20
      • 2021-07-04
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      • 2021-09-03
      相关资源
      最近更新 更多