首页 > 解决方案 > 我发送消息后,Discord.py bot 不断在 dm 上发送垃圾邮件

问题描述

尝试创建一个 dm mod 邮件机器人,当我发送消息时,它会不停地向同一条消息发送垃圾邮件。

代码:

def check(message):
    return message.author

@bot.event
async def on_message(message):
  await bot.process_commands(message)
  await bot.wait_for('message', check=check)
  await message.channel.send("Thanks for your message! Our staff team will reply to you as soon as possible.",delete_after=10)
  if message.author.bot:
    breakpoint
    e=bot.get_channel(746784415086149662)
    await e.send(f"**{message.author}**\n"
    f"{message.content}\n")

图片:

图片

标签: pythondiscord.py

解决方案


确保消息的作者不是机器人本身或其他机器人:

def check(message):
    return message.author

@bot.event
async def on_message(message):
  if message.author.bot:
    return
  await bot.process_commands(message)
  await bot.wait_for('message', check=check)
  await message.channel.send("Thanks for your message! Our staff team will reply to you as soon as possible.",delete_after=10)
  if not message.author.bot:
    e=bot.get_channel(746784415086149662)
    await e.send(f"**{message.author}**\n"
    f"{message.content}\n")

你有breakpoint哪个不会退出该功能。


推荐阅读