当静音用户离开服务器时,静音角色保存到静音用户
Posted
技术标签:
【中文标题】当静音用户离开服务器时,静音角色保存到静音用户【英文标题】:Mute Role Saves To The Muted User When They Leave From The Server 【发布时间】:2021-07-06 03:16:13 【问题描述】:这是我的代码,但是当某人离开服务器并重新加入时,我赋予静音角色时,该角色消失,当我使用 quick.db 时它不起作用,我应该怎么做才能使它起作用
const ms = require('ms')
const timer = new Map();
client.on('message', async nxt =>
if (nxt.content.startsWith(prefix + "role"))
var args = nxt.content.slice(prefix.length).trim().split(/ +/g);
if(!nxt.member.hasPermission('MANAGE_ROLES')) return nxt.channel.send("You don't have permissions")
var member = nxt.mentions.members.first();
var time = args[3]
var role = nxt.mentions.roles.first();
if(!role) return nxt.channel.send("I Can't find this role")
if(!member) return nxt.channel.send("Please Mention Someone")
if(!time) return nxt.channel.send("Please specify a time")
if (!time.endsWith("d"))
if (!time.endsWith("h"))
if (!time.endsWith("m"))
if (!time.endsWith("s"))
return nxt.channel.send('Please specify a time')
timer.set(nxt.author.id,
author:
tag: nxt.author.tag,
,
time: ms(time),
);
await member.roles.add(role)
nxt.react(`✅`)
setTimeout(async () =>
await member.roles.remove(role)
timer.delete(nxt.author.id);
, ms(time))
);```
How can I make it to give the mute role back ?
【问题讨论】:
【参考方案1】:首先在你的代码中添加这一行
//using quick.db
let muteTime = Date.now() + time;
db.set(`muted_$message.guild.id_$target.id`, muteTime);
然后当成员加入时这样做
client.on('guildMemberAdd', member =>
let MuteStatus = db.get(`muted_$member.guild.id_$member.id`);
if(!MuteStatus)
//This member wasn't muted
return(0);
if(MuteStatus > Date.now())
//He was muted and rejoined
//Give the role back
let TimeLeft = MuteStatus - Date.now();
await member.roles.add(MuteRole) //Give the muted role
setTimeout(async () =>
await member.roles.remove(MuteRole);
,TimeLeft);
);
【讨论】:
我做到了,谢谢兄弟的帮助,但问题是当有人重新加入服务器时,机器人没有被赋予静音角色:/以上是关于当静音用户离开服务器时,静音角色保存到静音用户的主要内容,如果未能解决你的问题,请参考以下文章