【问题标题】:discord.py logs how i can do that?discord.py 记录我该怎么做?
【发布时间】:2021-02-23 14:13:44
【问题描述】:

请帮帮我,我希望我的机器人发送日志(如 “用户进入频道”“消息已删除”“用户加入服务器") 提前致谢

@commands.Cog.listener()
  async def on_message_delete(self, message):

        deleted = Embed(
            description=f"Message deleted in {message.channel.mention}", color=0x4040EC
        ).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)

        deleted.add_field(name="Message", value=message.content)
        deleted.timestamp = message.created_at
        await channel.send(embed=deleted)

【问题讨论】:

  • 您的代码似乎是正确的,但您还没有告诉我们您的问题是什么……尽管我确实看到 channel 未定义。您可以使用channel = bot.get_channel(your_channel_id) 定义它。

标签: discord.py


【解决方案1】:

让我们举个例子,你想让它在用户加入时记录下来。当然,我个人使用客户端,并且没有齿轮,因此您可以根据需要更改它:

@client.event
async def on_user_join(self, member):
    logs_channel = client.get_channel(CHANNEL_ID_HERE)
    logs_channel.send(f"{member} has joined")
    # you can change the welcome message of course that is an example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-16
    • 2012-05-26
    • 1970-01-01
    • 2014-01-23
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多