英文:
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("https://meme-api.com/gimme").text
data = json.loads(content)
embed = discord.Embed(title=f"{data['title']}", color=discord.Colour.random()).set_image(url=f"{data['url']}")
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("https://meme-api.com/gimme").text
data = json.loads(content)
embed = discord.Embed(title=f"{data['title']}", color=discord.Colour.random()).set_image(url=f"{data['url']}")
await interaction.response.send_message(embed=embed)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论