简体   繁体   English

discord py - 如何检查成员在特定时间是否具有特定角色?

[英]discord py - How do I check if a member has a certain role for a specific time?

I want to kick members that have a specific role like "Prisoner" for 30 days and if yes, they should get kicked from server.我想将具有特定角色(例如“囚犯”)的成员踢 30 天,如果是,他们应该被踢出服务器。 But I don't know how I can do that or if this is even possible.但我不知道我怎么能做到这一点,或者这是否可能。

I tried that, but it doesn't work:我试过了,但它不起作用:

if role in member.roles for 30 days:
   await member.kick(reason=reason)

My question is: Is that possible?我的问题是:这可能吗? If yes, how?如果是,如何?

Even though I do not believe Discord saves the time a member is given a role, this is possible, all you would need to do is store the time when the role was given to the member.尽管我不相信 Discord 可以节省为成员分配角色的时间,但这是可能的,您需要做的就是存储将角色分配给成员的时间。 The only issue with this is that if the bot is closed in those thirty days, it would not be saved if you save it as simply a Python variable.唯一的问题是,如果机器人在这三十天内关闭,如果您将其保存为简单的 Python 变量,它将不会被保存。 If you stored the variable in a text file, local MYSQL database, or etc. it would be possible.如果您将变量存储在文本文件、本地 MYSQL 数据库等中,这是可能的。

Once you have that time stored, you should be able to check if it has been 30 days since in your if statement.一旦你存储了那个时间,你应该能够在你的 if 语句中检查它是否已经过了 30 天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM