首页 > 解决方案 > 嵌入命令不会发送,所有其他嵌入都会发送

问题描述

尽管所有其他嵌入都在工作,而且这是直接复制和粘贴,但“await bot.send_message(ctx.message.channel, embed=embed)”仍然在日志中发送错误,我不明白。“Bot”就是大多数人所说的客户端

我已经尝试使用 bot.say() 来查看通道是否是问题所在,并且我尝试重新排列 embed 语句以声明尽可能接近发送。代码中的所有其他嵌入都使用相同的格式,几乎没有任何更改,我什至复制粘贴它以使其准确。我尝试评论它的所有部分,唯一可能导致它的部分是 add_field 语句或初始设置之一,但我以前使用过它。

                title = "Rock Paper Scissors", 
                description = ctx.message.author.name, 
                color = discord.Color.red()
            )

            if(winner == "tie"):

                embed.set_thumbnail(url = "//https://i.imgur.com/RcnDdIR.png")
                embed.add_field(name= "Winner", value= "It was a tie! Both chose " + choice + "!", inline=False)
                embed.add_field(name= "Chips", value= users[ctx.message.author.id]["chips"], inline=False)

                await bot.send_message(ctx.message.channel, embed=embed)
                economy["rps"]["played"] += 1

                print (ctx.message.author.name + " Played Rock Paper Scissors, but tied")

                f = open(logname, "a")
                f.write(ctx.message.author.name + " Played Rock Paper Scissors, but tied\n")
                f.close()

"THE ERROR CODE
The Casiino is open
Running on Casiino
ID: 566778084175642635
Wildcard Played Rock Paper Scissors, but tied
Ignoring exception in command rps
Traceback (most recent call last):
  File "C:\Users\cjwil\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\cjwil\Desktop\casiino\bot.py", line 479, in rps
    await bot.send_message(ctx.message.channel, embed=embed)
  File "C:\Users\cjwil\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 1152, in send_message
    data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
  File "C:\Users\cjwil\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\http.py", line 200, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\cjwil\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\cjwil\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\cjwil\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: HTTPException: BAD REQUEST (status code: 400)"```

"I want The embed to send without any issues and without throwing errors."

标签: pythondiscorddiscord.py

解决方案


它看起来像是users[ctx.message.author.id]["chips"]一个Member对象。尝试显式获取其字符串表示以在嵌入中使用:

embed.add_field(name= "Chips", value=str(users[ctx.message.author.id]["chips"]), inline=False)

推荐阅读