【问题标题】:Embed in a command won't send, all other embeds do嵌入命令不会发送,所有其他嵌入都会发送
【发布时间】:2019-04-17 08:37:38
【问题描述】:

尽管所有其他嵌入都在工作,而且这是直接复制和粘贴,但“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."

【问题讨论】:

  • 如果您提供了正在返回的错误,这将很有用。阅读和理解错误消息是编程/调试的一个重要方面。
  • 请同时包含您正在使用的 discord.py 版本:print(discord.__version__)

标签: python discord discord.py


【解决方案1】:

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

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

【讨论】:

  • 谢谢,但遗憾的是它没有用,我在试验中评论了所有其他语句,似乎它来自其他 add_field 语句之一
  • 这可能是描述,尝试将其包装在 str 中。在某处您将此嵌入的一部分设置为等于 Member 对象
  • 我的意思是description = ctx.message.author 行。将其更改为description = str(ctx.message.author)
  • 好的,解决了这个问题,但现在我收到了一个有点差异的错误消息,我应该使用 author.name,我将主帖子中的错误日志更改为我现在得到的内容跨度>
  • 那个url 看起来不像是网址,也许就是这样
猜你喜欢
  • 2020-10-07
  • 2020-10-09
  • 2022-01-16
  • 2021-10-20
  • 1970-01-01
  • 2021-06-28
  • 2021-07-10
  • 2022-06-29
  • 2023-03-07
相关资源
最近更新 更多