When I created a bot by looking at the article Creating a bot that reads Discord chat aloud, ** emoji ID when reading out custom emoji on the server There was a problem that read aloud **, so we dealt with it as follows.
import re
def remove_custom_emoji(text):
pattern = r'<:[a-zA-Z0-9_]+:[0-9]+>' #Custom emoji pattern
return re.sub(pattern,'',text) #Replacement process
Custom emojis are in message.content
in the format<: emoji_name: emoji_id>
.
I created a pattern to remove it, passed it to re.sub ()
, and removed the custom emoji by replacing the matched part with a blank.
If you have a more accurate pattern, please leave a comment: bow_tone1:
I want to delete multiple strings in Python-use re.sub Discord Bot Portal JP (Twitter)
Recommended Posts