首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AIOHTTP meme命令discord.py

AIOHTTP meme命令discord.py
EN

Stack Overflow用户
提问于 2019-03-08 20:24:31
回答 3查看 6.3K关注 0票数 1

我正在制作一个不和谐的机器人,我试图制作一个随机的meme命令,下面是我的错误和代码:

代码语言:javascript
复制
@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)
代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-03-08 20:32:14

正如错误中所述,函数set_image(url)只有1个参数,而您给了它2个参数。有关嵌入消息,请查看this线程。

票数 1
EN

Stack Overflow用户

发布于 2020-05-30 15:48:16

代码语言:javascript
复制
@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)
票数 2
EN

Stack Overflow用户

发布于 2021-06-07 02:49:43

我个人给你的建议是使用https://meme-api.herokuapp.com/gimme/dankmemes来拉取memes.And,如果你有兴趣添加一个标题,使用这个命令来添加一个标题到你的嵌入:

代码语言:javascript
复制
title = res['data']['children'][random.randint(0,25]["data"]["title"]I 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55063189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档