消息侦听器工作不正常discord.py bot

2024-06-08 13:58:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个机器人,而我使用的消息侦听器没有拾取其他人的消息:

@bot.event
async def on_message(message):
  chnl = message.channel.name
  ts = time.time()
  athr = message.author.display_name
  st = datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
  
  
  with open("logs/chat.txt", "a") as text_file:
    #print(f"<{message.created_at} | {athr}> {message}", file=text_file)
    print(f"_(#{chnl}) <{st} | {athr}> {message.content}", file=text_file)
    return athr, st, message.content
  await bot.process_commands(message)

这似乎是个简单的问题,但我看不出有什么不对


load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("DISCORD_GUILD")


bot = commands.Bot(command_prefix=';')

Tags: textnametoken消息messagetimebotcontent