我想阻止我的用户在同一封邮件中使用太多大写字母(即输入完整的CAPS LOCK)。我试过了,但是如果他们在大写字母之间加空格似乎不起作用。这是我当前的代码:
client.on("message", async (msg) => {
let sChannel = msg.guild.channels.find((c) => c.name === "guard-log");
if (msg.channel.type === "dm") return;
if (msg.author.bot) return;
if (msg.content.length > 15) {
if (db.fetch(`capslock_${msg.guild.id}`)) {
let caps = msg.content.replace(" ", "").toUpperCase();
if (msg.content == caps) {
if (!msg.member.hasPermission("ADMINISTRATOR")) {
if (!msg.mentions.users.first()) {
msg.delete();
let embed = new Discord.RichEmbed()
.setColor(0xffa300)
.setFooter("Retro Guard", client.user.avatarURL)
.setTitle("Caps-lock Engel")
.setDescription("Fazla caps lock kullanımı yakalandı!")
.addField("Kanal Adı", msg.channel.name, true)
.addField(
"Kişi",
"Kullanıcı: " + msg.author.tag + "\nID: " + msg.author.id,
true
)
.addField("Engellenen mesaj", "```" + msg.content + "```", true)
.setTimestamp();
sChannel.send(embed);
return msg.channel
.send(`${msg.author} fazla caps kullanıyorsun.`)
.then((m) => m.delete(5000));
}
}
}
}
}
});
答案 0 :(得分:0)
在每个字母上使用.toUpperCase()
并将其与大写字母进行比较,如果相同,则大写。否则,您实际上不需要任何数据库。尝试遵循以下代码:
client.on("message", async msg => {
let sChannel = msg.guild.channels.find(c => c.name === "guard-log");
if (msg.channel.type === "dm" || msg.author.bot || msg.content.length < 15) return;
// Use `||` (OR) to make it cleaner.
let non_caps, caps;
// Create the variables.
for (x=0;x<msg.content.length;x++) {
if (msg.content[x].toUpperCase() === msg.content[x]) caps++;
else non_caps++;
}
// `caps` is the amount of capital letters, while `non_caps` is the amount of non-capital letters. This checks for each letter of the message and gets the amount of `caps` and `non_caps`.
const textCaps = (caps / message.content.length) * 100;
// Gets a percentage of the capital letters.
if (textCaps >= 60 && !msg.member.permissions.has('ADMINISTRATOR')) {
// If the capital letters is over or equals to 60% of the message,
// and if the user isn't an ADMINISTRATOR, then...
let embed = new Discord.RichEmbed()
.setColor(0xffa300)
.setFooter('Retro Guard', client.user.avatarURL)
.setTitle("Caps-lock Engel")
.setDescription("Fazla caps lock kullanımı yakalandı!")
.addField("Kanal Adı", msg.channel.name, true)
.addField('Kişi', 'Kullanıcı: '+ msg.author.tag +'\nID: '+ msg.author.id, true)
.addField('Engellenen mesaj', "```" + msg.content + "```", true)
.setTimestamp()
sChannel.send(embed);
msg.delete(); // Deletes the capped message.
return msg.reply(`fazla caps kullanıyorsun.`)
// `message.reply()` mentions the user that sent the message and is cleaner.
.then(m => m.delete(5000))
}
})
请小心,因为如果他们放置过多的大写字母(包括他们引用某人,无论他们是否故意),这都会删除该消息。
如果您仍然不了解,请参考以下内容: