【问题标题】:Bot doesn't send the requested message机器人不发送请求的消息
【发布时间】:2020-12-29 17:11:41
【问题描述】:

我正在开发一个支持机器人,但它并不完全符合预期。机器人不会直接进入 DMS,而是在触发器中发送消息。当我运行命令时,我必须在它之前放置一条消息 DMS 我。然后它会运行所有步骤,但在我 dm 后,它会发送原始上下文消息。

@bot.command()
async def contact(ctx, *, message):
  channel = bot.get_channel(766311471063498852)
  embed1 = discord.Embed(colour=discord.Colour.blue())
  embed1.add_field(name="Your support lays behind this bot.", value="Do you need support?", inline=True)
  embed_1sent = await ctx.author.send(embed=embed1)
  embed2 = discord.Embed(colour=discord.Colour.blue())
  embed2.add_field(name="Alright.", value="What would you like to send to staff?", inline=True)
  await embed_1sent.add_reaction("<a:CheckMark:768095274949935146>")
  await embed_1sent.add_reaction("<a:XMark:768095331555606528>")
  def check(reaction, member):
    return member == member and str(reaction.emoji)== "<a:CheckMark:768095274949935146>"

  try:
   reaction, member = await bot.wait_for('reaction_add', timeout=60.0, check=check)
  except asyncio.Timeout.Error:
    await member.send("You took too long. Command cancelled.")
  else:
    await member.send(embed=embed2)
    await channel.send(f"From: {member} {message}")
  def check(reaction, member):
    return member == member and str(reaction.emoji)== "<a:XMark:768095331555606528"

  try:
    reaction, member = await bot.wait_for('reaction_add', timeout=60.0, check=check)
  except asyncio.Timeout.Error:
    await member.send("You took too long. Command cancelled.")
  else:
    await member.send("Command promt cancelled.")

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:

    DM 用户的正确方法是使用.create_dm() 方法。所以在发送你的嵌入时,你应该有更多这样的东西。

    embedOne = discord.Embed(
        color = discord.Color.Blue()
    )
    
    embedOneadd_field(name = "Your support lays behind this bot.", value = "Do you need support?", inline = True)
    
    userDM = ctx.author.create_dm()
    embedOneMessage = await userDM.send(embed = embedOne)
    

    【讨论】:

    • 这对我有用,但我在第一次尝试时遇到了同样的问题。它需要在触发消息中包含一条消息,然后在发送消息之前执行 DMing 您的过程。
    猜你喜欢
    • 2021-10-16
    • 2014-09-18
    • 2019-06-13
    • 2020-11-02
    • 2021-08-19
    • 2021-05-08
    • 2020-11-23
    • 2017-03-19
    • 2012-09-21
    相关资源
    最近更新 更多