<legend id='WBnNo'><style id='WBnNo'><dir id='WBnNo'><q id='WBnNo'></q></dir></style></legend>

<tfoot id='WBnNo'></tfoot>
      <bdo id='WBnNo'></bdo><ul id='WBnNo'></ul>

    <small id='WBnNo'></small><noframes id='WBnNo'>

      1. <i id='WBnNo'><tr id='WBnNo'><dt id='WBnNo'><q id='WBnNo'><span id='WBnNo'><b id='WBnNo'><form id='WBnNo'><ins id='WBnNo'></ins><ul id='WBnNo'></ul><sub id='WBnNo'></sub></form><legend id='WBnNo'></legend><bdo id='WBnNo'><pre id='WBnNo'><center id='WBnNo'></center></pre></bdo></b><th id='WBnNo'></th></span></q></dt></tr></i><div id='WBnNo'><tfoot id='WBnNo'></tfoot><dl id='WBnNo'><fieldset id='WBnNo'></fieldset></dl></div>
      2. 如何为我的 discord.py 机器人获取随机 subreddit 图像

        时间:2023-10-11

        <small id='UqxT2'></small><noframes id='UqxT2'>

          <i id='UqxT2'><tr id='UqxT2'><dt id='UqxT2'><q id='UqxT2'><span id='UqxT2'><b id='UqxT2'><form id='UqxT2'><ins id='UqxT2'></ins><ul id='UqxT2'></ul><sub id='UqxT2'></sub></form><legend id='UqxT2'></legend><bdo id='UqxT2'><pre id='UqxT2'><center id='UqxT2'></center></pre></bdo></b><th id='UqxT2'></th></span></q></dt></tr></i><div id='UqxT2'><tfoot id='UqxT2'></tfoot><dl id='UqxT2'><fieldset id='UqxT2'></fieldset></dl></div>
          <tfoot id='UqxT2'></tfoot>
            <bdo id='UqxT2'></bdo><ul id='UqxT2'></ul>

              • <legend id='UqxT2'><style id='UqxT2'><dir id='UqxT2'><q id='UqxT2'></q></dir></style></legend>
                  <tbody id='UqxT2'></tbody>
                1. 本文介绍了如何为我的 discord.py 机器人获取随机 subreddit 图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在异步 python 中制作一个不和谐的机器人.我希望机器人在我执行命令(前缀!)示例时发布 随机 图片!meme.这会从 subreddit 中调出一张随机图片,在这种情况下是 memes subreddit.我已经开始了我想要的,但我需要随机 subreddit 位的帮助.

                  I am making a discord bot in async python. I want the bot to post a random picture when I do a command (prefix !) example !meme. This would bring up a random picture from a subreddit, in this case the memes subreddit. I have made the start to what I want, but I need help with the random subreddit bit.

                  import discord
                  import praw
                  from discord.ext import commands
                  
                  bot = commands.Bot(description="test", command_prefix="!")
                  
                  @bot.command()
                  async def meme():
                      await bot.say(---)   
                      #--- WOULD BE THE REDDIT URL
                      bot.run("TOKEN")
                  

                  我将如何使用 discord.py 和 PRAW 来做到这一点?

                  推荐答案

                  以下代码将从 memes subreddit 中获取随机帖子.目前它会从热门版块的前 10 篇帖子中随机提交.

                  The below code will fetch a random post from the memes subreddit. Currently it picks a random submission from the top 10 posts from the hot section.

                  import praw
                  import random
                  from discord.ext import commands
                  
                  bot = commands.Bot(description="test", command_prefix="!")
                  
                  reddit = praw.Reddit(client_id='CLIENT_ID HERE',
                                       client_secret='CLIENT_SECRET HERE',
                                       user_agent='USER_AGENT HERE')
                  
                  @bot.command()
                  async def meme():
                      memes_submissions = reddit.subreddit('memes').hot()
                      post_to_pick = random.randint(1, 10)
                      for i in range(0, post_to_pick):
                          submission = next(x for x in memes_submissions if not x.stickied)
                  
                      await bot.say(submission.url)
                  
                  bot.run('TOKEN')
                  

                  这篇关于如何为我的 discord.py 机器人获取随机 subreddit 图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:discord.py 中的 Cog 和 Extension 有什么区别? 下一篇:(discord.py) 有没有办法让 on_message 事件查看嵌入式

                  相关文章

                  最新文章

                  <legend id='RkEDG'><style id='RkEDG'><dir id='RkEDG'><q id='RkEDG'></q></dir></style></legend>

                    <i id='RkEDG'><tr id='RkEDG'><dt id='RkEDG'><q id='RkEDG'><span id='RkEDG'><b id='RkEDG'><form id='RkEDG'><ins id='RkEDG'></ins><ul id='RkEDG'></ul><sub id='RkEDG'></sub></form><legend id='RkEDG'></legend><bdo id='RkEDG'><pre id='RkEDG'><center id='RkEDG'></center></pre></bdo></b><th id='RkEDG'></th></span></q></dt></tr></i><div id='RkEDG'><tfoot id='RkEDG'></tfoot><dl id='RkEDG'><fieldset id='RkEDG'></fieldset></dl></div>

                      • <bdo id='RkEDG'></bdo><ul id='RkEDG'></ul>

                      <small id='RkEDG'></small><noframes id='RkEDG'>

                      <tfoot id='RkEDG'></tfoot>