#Why my discord bot still remove Emoji?

14 messages · Page 1 of 1 (latest)

lucid shoal
#

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);
              }
          }
      }
  }
analog schooner
#

yeah unicode emojis are sent as their actual characters, not as :emojiName: or whatever

nocturne oak
#

If you're doing it manually you'd probably have to write a regex that's unicode aware (there's a /u flag, IIRC) and include the range of unicode characters

#

Or you could try the reverse and try having a list of characters that's not allowed - though I guess with CJK characters that's probably similarly difficult.

#

TBH, this probably just isn't something I would try to automate with a bot - there's a lot of cases where people use non-standard-English-characters

analog schooner
#

i believe djs has a emoji regex built-in

#

but yeah you'd be disallowing pretty simple stuff like math symbols and arrows as well

nocturne oak
#

Looks like there's some built-in character classes

#

(╯°□°)╯︵ ┻━┻
But like, stuff like this would be banned and that seems unnecessary to me.

#

/flip is literally a built-in discord command

lucid shoal
#

tysm

nocturne oak
#

!close