我当时正在开发一款不和谐的漫游器以及一个验证频道。我希望用户仅键入/verify
命令:他们键入的除/verify
以外的每条消息或命令都应自动删除。我该怎么办?
当前代码:
if (command === "verify") {
if (message.channel.id !== "ChannelID") return;
let role = message.guild.roles.find(rol => rol.name === 'Member')
const reactmessage = await message.channel.send('React with to verify yourself!');
await reactmessage.react('');
const filter = (reaction, user) => reaction.emoji.name === '' && !user.bot;
const collector = reactmessage.createReactionCollector(filter, {
time: 15000
});
collector.on('collect', async reaction => {
const user = reaction.users.last();
const guild = reaction.message.guild;
const member = guild.member(user) || await guild.fetchMember(user);
member.addRole(role);
message.channel.send(`Verification Complete.. ${member.displayName}. You have got access to server. `)
});
message.delete();
}
答案 0 :(得分:0)
您可以在client.on('message')
侦听器的顶部添加一个检查:
client.on('message', message => {
let verified = !!message.member.roles.find(role => role.name == 'Member');
// ... command parsing ect...
if (!verified && command == 'verify') {...}
else if (verified) {
// other commands...
}
});