在 Discord 中踢出 "ghosts" 位用户
Kick "ghosts" users in Discord
我不知道如何设法创建一个函数或一些东西来验证用户在一段时间内没有向 discord 服务器发送任何东西并踢这个用户不活跃。它不像修剪用户,因为修剪会踢掉当时没有登录的用户。
我正在使用来自 Rapptz 的 discord.py,但你可以(如果可能的话)给我一个你想要的任何包装器的例子。
如果您正在重写,可以使用 history
异步迭代器查找用户的最后一条消息。
文档中的示例
counter = 0
# Limit is not required, but can make this a really slow operation if you don't use it.
async for message in channel.history(limit=200):
if message.author == client.user:
counter += 1
另一种方法是在 JSON 或任何其他使用 on_message()
事件的数据库中跟踪 'last message sent' 的时间戳。然后,您可以执行清除命令或每 X 秒执行一次清除。
如果您不使用重写或者您使用的服务器有很多成员,后者可能是理想的选择。
如果你使用on_message
来处理时间戳,你可以这样实现
@bot.event
async def on_message(msg):
# GET user (msg.author) and edit their timestamp on database
我不知道如何设法创建一个函数或一些东西来验证用户在一段时间内没有向 discord 服务器发送任何东西并踢这个用户不活跃。它不像修剪用户,因为修剪会踢掉当时没有登录的用户。
我正在使用来自 Rapptz 的 discord.py,但你可以(如果可能的话)给我一个你想要的任何包装器的例子。
如果您正在重写,可以使用 history
异步迭代器查找用户的最后一条消息。
文档中的示例
counter = 0
# Limit is not required, but can make this a really slow operation if you don't use it.
async for message in channel.history(limit=200):
if message.author == client.user:
counter += 1
另一种方法是在 JSON 或任何其他使用 on_message()
事件的数据库中跟踪 'last message sent' 的时间戳。然后,您可以执行清除命令或每 X 秒执行一次清除。
如果您不使用重写或者您使用的服务器有很多成员,后者可能是理想的选择。
如果你使用on_message
来处理时间戳,你可以这样实现
@bot.event
async def on_message(msg):
# GET user (msg.author) and edit their timestamp on database