python - AIOHTTP meme 命令discord.py

标签 python discord discord.py aiohttp

我正在制作一个不和谐的机器人,我正在尝试制作一个随机模因命令,这是我的错误和代码:

@client.command(pass_context=True)
async def meme(ctx):
    embed = discord.Embed(title="meme", description="test")

    async with aiohttp.ClientSession() as cs:
        async with cs.get('https://www.reddit.com/r/dankmemes/new.json?sort=hot') as r:
            res = await r.json()
            embed.set_image(res['data']['children'] [random.randint(0, 25)]['data']['url'])
            await client.say(embed=embed)
Ignoring exception in command meme
Traceback (most recent call last):
  File "C:\Users\atill\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "C:\Users\atill\Downloads\Epic Bot\server.py", line 165, in meme
    embed.set_image(res['data']['children'] [random.randint(0, 25)]['data']['url'])
TypeError: set_image() takes 1 positional argument but 2 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\atill\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:\Users\atill\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\atill\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: set_image() takes 1 positional argument but 2 were given

I'm not sure how to make it so it is in an embed aswell

最佳答案

@client.command(pass_context=True)
async def meme(ctx):
    embed = discord.Embed(title="", description="")

    async with aiohttp.ClientSession() as cs:
        async with cs.get('https://www.reddit.com/r/dankmemes/new.json?sort=hot') as r:
            res = await r.json()
            embed.set_image(url=res['data']['children'] [random.randint(0, 25)]['data']['url'])
            await ctx.send(embed=embed)

关于python - AIOHTTP meme 命令discord.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55063189/

相关文章:

python - Discord.py计算器: Multiple Values?

python - 匹配两个列表之间的相似元素

python - 索引维基百科的链接以制作图表

javascript - 为什么我的清除命令出错了?

php - Discord PHP 从 channel ID 创建邀请链接

c# - DSharpPlus - 对现有消息的 WaitForReaction

python - python中PCA的内存错误

python - 用两个列表中的键、值初始化 dict

python - 当成员不在 JSON 文件中时,Discord.py 机器人无法发送消息

python-3.x - Discord.py 删除除 pin 消息之外的所有消息