Im making a discord bot that only remove "English" word
but it allow to use special letter include ' " : ; etc... so but the problem is it also remove the Emoji
if (message.channel.id === '1291999694381256724') {
const allowedCharacters = /^[a-zA-Z0-9\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>/?]+$/;
if (!allowedCharacters.test(message.content)) {
try {
await message.delete();
try {
let channelName = 'general';
if (message.channel.type === ChannelType.GuildText) {
channelName = (message.channel as TextChannel).name;
}
await message.author.send(`Your message in #${channelName} was deleted because it contained characters that are not allowed in this English-only channel. Please use only English letters, numbers, and common punctuation marks.`);
} catch (dmError) {
console.error("Could not send DM to user", dmError);
}
let channelIdentifier = `channel ID ${message.channel.id}`;
if (message.channel.type === ChannelType.GuildText) {
channelIdentifier = `#${(message.channel as TextChannel).name}`;
}
sendLogs(`Deleted a message from ${message.author.username} in ${channelIdentifier} for using non-allowed characters.`);
console.log(`Deleted a message from ${message.author.username} in ${channelIdentifier} for using non-allowed characters.`);
} catch (error) {
if (error instanceof DiscordAPIError && error.code === 10008) {
console.log(`Message ${message.id} was already deleted or not found.`);
} else {
console.error('Error deleting message:', error);
}
}
}
}