Discord.py 随机迷因 API

huangapple go评论62阅读模式
英文:

Discord.py random meme API

问题

Trying to make a random meme command.

Tried 2 different ways, both end up with the same error.

discord.app_commands.errors.CommandInvokeError: Command 'test' raised an exception: NotFound: 404 Not Found (error code: 10015): Unknown Webhook

Both of my commands

@bot.tree.command()
async def meme(interaction: discord.Interaction):
    content = requests.get("https://meme-api.com/gimme").text
    data = json.loads(content,)
    meme = discord.Embed(title=f"{data['title']}")
    await interaction.followup.send(embed=meme)

and

@bot.tree.command()
async def test(interaction: discord.Interaction):
    embed = discord.Embed(title='Meme', description=None)

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

Trying to make a random meme command.

Tried 2 different ways, both end up with the same error.

discord.app_commands.errors.CommandInvokeError: Command 'test' raised an exception: NotFound: 404 Not Found (error code: 10015): Unknown Webhook

Both of my commands

async def meme(interaction: discord.Interaction):
    content = requests.get("https://meme-api.com/gimme").text
    data = json.loads(content,)
    meme = discord.Embed(title=f"{data['title']}")
    await interaction.followup.send(embed=meme)

and

@bot.tree.command()
async def test(interaction: discord.Interaction):
    embed = discord.Embed(title='Meme', description=None)

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

</details>


# 答案1
**得分**: 1

以下是您要翻译的内容:

"Working code is below, tbh idk what i did but ended up Alt+z and worked on original code, fixed color=discord.Colour.random() and it worked :D

```@bot.tree.command()
async def meme(interaction: discord.Interaction):
    content = requests.get(&quot;https://meme-api.com/gimme&quot;).text
    data = json.loads(content)
    embed = discord.Embed(title=f&quot;{data[&#39;title&#39;]}&quot;, color=discord.Colour.random()).set_image(url=f&quot;{data[&#39;url&#39;]}&quot;)
    await interaction.response.send_message(embed=embed)"

<details>
<summary>英文:</summary>

Working code is below, tbh idk what i did but ended up Alt+z and worked on original code, fixed color=discord.Colour.random() and it worked :D

```@bot.tree.command()
async def meme(interaction: discord.Interaction):
    content = requests.get(&quot;https://meme-api.com/gimme&quot;).text
    data = json.loads(content)
    embed = discord.Embed(title=f&quot;{data[&#39;title&#39;]}&quot;, color=discord.Colour.random()).set_image(url=f&quot;{data[&#39;url&#39;]}&quot;)
    await interaction.response.send_message(embed=embed)

</details>



huangapple
  • 本文由 发表于 2023年5月18日 07:16:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76276765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定