【问题标题】:the embed do not send and i didint have errors嵌入不发送,我没有错误
【发布时间】:2021-07-11 17:19:30
【问题描述】:
@commands.has_permissions(administrator=True)
@bot.command()
async def ban(ctx, member : discord.Member, *, reason=None):
    await member.send (f"{member.mention} text  {ctx.guild.name}  for the reason: {reason} ")
    await  member.ban(reason=reason)
    await ctx.send (title=f"**__text:__**", description=f"{member.mention} \n  **text:** \n *{reason}*", timestamp=datetime.datetime.utcnow(),color=discord.Color.blue()) .embed.set_footer (text="text ", icon_url="url")
    if reason is None:
        reason = f"{member.mention} was banned without reasons {ctx.guild.name} "
        return reason

我没有错误,并且嵌入 didint 发送

【问题讨论】:

  • 第5行的语法并不是真正有效的python语法
  • ??????????它是
  • 我使用 discord py{member.mention} 它在 discord py 上可能阅读了文档,我使用了 f 字符串
  • 不,不是那个,这个 - timestamp=datetime.datetime.utcnow(),color=discord.Color.blue()) .embed.set_footer (text="text ", icon_url="url")
  • 哦,是的,也许它不起作用所以......

标签: python discord.py embed


【解决方案1】:

我会建议您更好的划分,以尽量减少错误的来源。最好的方法是定义一个嵌入。

看看下面的代码:

@commands.has_permissions(administrator=True)
@bot.command()
async def ban(ctx, member : discord.Member, *, reason=None):
    await member.send(f"{member.mention} text  {ctx.guild.name}  for the reason: {reason} ")
    await member.ban(reason=reason)

    embed = discord.Embed(color=discord.Color.blue())
    embed.title = "__Text__" # Title is always bold
    embed.description = f"{member.mention} \n  **text:** \n *{reason}*"
    embed.timestamp = datetime.datetime.utcnow() # New timestamp
    embed.set_footer(text="This is a test", icon_url="PassUrl")
    await ctx.send (embed=embed) # Send defined embed

    if reason is None:
        reason = f"{member.mention} was banned without reasons {ctx.guild.name} "
        return await ctx.send(f"{reason}")

还要注意适当的缩进,可能是空格太多等

也许还可以看看docs 以及如何创建有效的嵌入。

【讨论】:

  • 嗯,我看到我尝试在 1 行代码中添加许多嵌入,感谢您的支持!
  • 您也可以将其放在一行中,但这可能会导致您一开始看不到的错误。这样你的程序应该会告诉你你做错了什么(例如 PyCharm)。
猜你喜欢
  • 2019-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-14
  • 2021-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多