简体   繁体   English

如何在公会 discordjs V12 中从用户中删除角色?

[英]How to remove role from user in guild discordjs V12?

I have an economy system on my discord server and players can buy VIP for 30 days.我的 discord 服务器上有一个经济系统,玩家可以购买 30 天的 VIP。 Data are saved in firestore cloud database.数据保存在 Firestore 云数据库中。 The bot checks every 4 hours if someone has over his VIP and it should remove it but it doesn't work.该机器人每 4 小时检查一次是否有人超过了他的 VIP,它应该删除它,但它不起作用。

Console says: Cannot read property 'roles' of undefined.控制台说: Cannot read property 'roles' of undefined.

Here is the part of the code that does not work:这是代码中不起作用的部分:

let server = bot.guilds.cache.get("472822894649540608");
let player = server.members.cache.get('452773419105255435');
player.roles.remove('476112578280685568');

Thanks for the help谢谢您的帮助

You shouldn't assume the member is in the cache.您不应该假设该成员在缓存中。 In this case, it wasn't.在这种情况下,它不是。 Instead, always fetch() the member:相反,总是fetch()成员:

let server = bot.guilds.cache.get("472822894649540608");
let player = await server.members.fetch('452773419105255435');
player.roles.remove('476112578280685568');

PS: I think in v11 that used to work, but not anymore in v12. PS:我认为在 v11 中可以使用,但在 v12 中不再适用。

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

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