【发布时间】:2021-02-22 11:19:50
【问题描述】:
例如这里的代码,它可以工作,但有一些名称,例如https://api.ashcon.app/mojang/v2/user/TonTon70 太长并给出此错误“长度必须为 1024 或更少” 所以我看到一些机器人将长字段作为带有左右箭头的页面发送
import discord
from discord.ext import commands
import requests
import json
from tabulate import tabulate
@client.command()
async def namehistory(ctx,*username):
async with ctx.typing():
embed = discord.Embed(
discription = "discription",
color = discord.Color.green()
)
if not username:
embed.add_field(name="Name History", value="Username not supplied!", inline=False)
await ctx.send(embed=embed)
return
nurl = "https://api.ashcon.app/mojang/v2/user/" + username[0]
nr = requests.get(url=nurl)
data = nr.json()
if "username" in data and data.get("username") != 'null':
nhistory = data['username_history']
nhistory = tabulate(nhistory,headers="keys")
embed.add_field(name="Name History", value=f"```{nhistory}```", inline=False)
await ctx.send(embed=embed)
else:
await ctx.send("Wrong username!")
【问题讨论】:
-
嵌入字段本身有 1024 个字符的限制(您可以在 discord.com/developers/docs 的某处找到限制)。您应该尝试将它们拆分为多个字段或发送多条消息
标签: python json python-requests discord discord.py