discord.py嵌入描述、缩略图不显示且set_thumbnail调用报错如何解决
问题原因及修复方案
错误1:Embed描述不展示
你初始化Embed时参数名拼写错误,代码中写的discription是无效参数,正确参数名为description,拼写错误导致描述字段没有被正确赋值,因此无法正常展示。
错误2:set_thumbnail方法报错
discord.py中set_thumbnail()、set_footer()这类Embed属性设置方法,不接受位置参数,所有参数都必须以关键字参数的形式传入。你直接把图片URL、页脚文本作为位置参数传入,会触发参数数量不匹配的错误。你当前代码中的set_footer也存在同样问题,只是代码执行到set_thumbnail时就提前抛出异常,还未执行到set_footer环节。
修复后完整代码
@client.event async def on_command_error(ctx, error): if isinstance(error, commands.MissingRequiredArgument): # 修正description拼写错误 emb = discord.Embed(color=0xda70d6,title = 'Issue with command', description = 'Using the correct commands is helpful, if you dont know them use "_help"') emb.set_author(name = 'Alert', icon_url='https://i.pinimg.com/474x/60/5e/ac/605eac3124c4885e067002cdd4ff684a.jpg') # 显式指定url关键字参数 emb.set_thumbnail(url='https://library.kissclipart.com/20191119/ww/kissclipart-help-icon-help-and-support-icon-92018307fcf5c4fa.png') # 显式指定text关键字参数 emb.set_footer(text='If you have any questions just DM the onwer Saly_Derek#0031 or Co-Owner Salty_Troye#0540') await ctx.send(embed=emb)
内容的提问来源于stack exchange,提问作者Derek
相关产品推荐
相关产品推荐

