我正在异步python中制造一个不和谐的机器人。当我执行命令时,我希望机器人发布一个随机图片(前缀!)比如!迷因。这将显示一个随机的图片从一个减法,在这种情况下,模因分红。我已经开始做我想要的,但我需要帮助的随机减法比特。
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?
发布于 2018-04-17 16:01:54
下面的代码将从模因subreddit中获取一个随机的帖子。目前,它从热门部分的前10个帖子中随机选出一个提交。
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')发布于 2020-12-31 02:53:10
@client.command(aliases=['Meme'])
async def meme(ctx):
reddit = praw.Reddit(client_id='XXXX',
client_secret='XXXX',
user_agent='XXXX')
submission = reddit.subreddit("memes").random()
await ctx.send(submission.url)https://stackoverflow.com/questions/49881935
复制相似问题