当我的 Discord 机器人加入服务器时,有没有办法 运行 一个函数? - Discord.py 重写

Is there a way to run a function when my Discord bot joins a server? - Discord.py Rewrite

我正在使用 discord.py 重写创建 Discord 机器人。

当我邀请它加入服务器时,我希望它将服务器中的所有用户添加到一个字典中,该字典将存储他们的统计信息等。

我环顾四周,似乎找不到解决这个问题的方法。

我想要这样的东西:

@bot.event
async def on_bot_invite(guild):
    ...

有人可以帮忙吗?

没有"discord.py rewrite"了。 discord.py 的重写分支现在只是 v1。
参见 https://discordpy.readthedocs.io/en/latest/migrating.html

您要查找的事件可能是 on_guild_join
然后,您可以使用传递给该事件处理程序的 members attribute of the Guild 对象。