我有我的discord机器人程序日志消息,因为它们是由我的服务器中的用户发送的,但每当其他机器人程序发送消息时,我都希望机器人程序不要在那里记录消息。我该如何进行
日志代码:
@client.event
async def on_message(ctx):
if ctx.author != client.user:
log_msg = client.get_channel(1003447126501625856)
await log_msg.send(f"""**Message sent by: {ctx.author.mention} in {ctx.channel.mention}.
Message:** "{ctx.content}" """)
print(f"""**Message sent by: {ctx.author} in {ctx.channel}.
Message:** "{ctx.content}" """)
您应该检查消息的传入作者是否是机器人。如果是,则返回None。
async def on_message(ctx):
# return if the message is from a bot
if ctx.author.bot: return # noqa: E701
来源:
- 不和谐.py 2.0->Github
- discord.py 2.0->文件