我的discord.py机器人中有2个meme命令。我正在使用redditeasy api,因为有人告诉我它比asyncpraw和praw更快(这是真的)
我的问题是:有没有办法将子项随机分配?我的意思是,api应该从给定的子Reddit列表中随机选取一个子Reddit,然后从随机选取的子Reddit中随机选取一篇文章
我试着做:
random\u sub\u list=random.choice['Subreddits here']
然后在subreddit中传递该变量,但不起作用
这是我的密码:
#memes
@bot.command(aliases = ['m'])
async def meme(ctx):
post = redditeasy.AsyncSubreddit(subreddit = 'dankmemes', client_id='id here',
client_secret = 'secret',
user_agent = 'memes')
postoutput = await post.get_post()
em2 = discord.Embed(title = f'{postoutput.title}')
url = postoutput.content
em2.set_image(url = url)
await ctx.send(embed = em2)
#narutomemes
@bot.command(aliases = ['Nmeme', 'NMEME', 'nm', 'NM', 'Nm'])
async def nmeme(ctx):
post = redditeasy.AsyncSubreddit(subreddit = 'narutomemes', client_id='id here',
client_secret = 'secret',
user_agent = 'memes')
postoutput = await post.get_post()
em3 = discord.Embed(title = f'{postoutput.title}')
url = postoutput.content
em3.set_image(url = url)
await ctx.send(embed = em3)
我真的更喜欢https://meme-api.herokuapp.com/gimme/(你的subreddit)这将从你提供的subreddit中随机返回一篇文章,但subreddit必须有照片(它将以JSON的形式返回) 这是我目前的meme代码
https://github.com/D3vd/Meme_Api这是文件
我试过这样的东西
但是没有了discord机器人,它工作得非常完美。这些帖子是从2个子网站中随机抽取的。我还使用了你的客户机密
小心分享这个秘密。有些人可能会滥用它
相关问题 更多 >
编程相关推荐