How to get rid of server custom emoji in message.content

Bugs and countermeasures

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

Commentary

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:

reference

I want to delete multiple strings in Python-use re.sub Discord Bot Portal JP (Twitter)

Recommended Posts

How to get rid of server custom emoji in message.content
How to get rid of long comprehensions
How to get the number of digits in Python
manage to get rid of heavy pyls in vim-lsp
How to get a list of built-in exceptions in python
How to get an overview of your data in Pandas
How to get a quadratic array of squares in a spiral!
Get custom emoji registered in slack
How to get the vertex coordinates of a feature in ArcPy
How to get a stacktrace in python
Get rid of DICOM images in Python
How to get rid of the "Tags must be an array of hashes." Error in the qiita api
How to keep track of work in Powershell
Summary of how to import files in Python 3
How to get results from id in Celery
How to get help in an interactive shell
Summary of how to use MNIST in Python
How to get dictionary type elements of Python 2.7
How to get the files in the [Python] folder
How to get a list of files in the same directory with python
How to get the variable name itself in python
How to get multiple model objects randomly in Django
How to display multiple images of galaxies in tiles
How to get RGB and HSV histograms in OpenCV
How to write custom validations in the Django REST Framework
[Go language] How to get terminal input in real time
I want to get rid of import warnings from Pyright and pylint in VS Code
Get rid of python's KeyError
[Linux] [C / C ++] Summary of how to get pid, ppid, tid
[Question] How to get data of textarea data in real time using Python web framework bottle
I tried "How to get a method decorated in Python"
How to develop in a virtual environment of Python [Memo]
How to get Instruction Pointer (= program counter) in Linux kernel
Comparison of how to use higher-order functions in Python 2 and 3
How to get the last (last) value in a list in Python
How to get all the keys and values in the dictionary
Summary of how to write .proto files used in gRPC
How to develop in Python
[Shell] How to get the remote default branch in Git
How to get a list of links from a page from wikipedia
How to display a specified column of files in Linux (awk)
How to get and set the NTP server name by DHCP
How to handle multiple versions of CUDA in the same environment
Overview of how to create a server socket and how to establish a client socket
How to determine the existence of a selenium element in Python
How to implement Java code in the background of RedHat (LinuxONE)
How to know the internal structure of an object in Python
Try to get a list of breaking news threads in Python.
How to get all the possible values in a regular expression
How to change the color of just the button pressed in Tkinter
How to get the ID of Type2Tag NXP NTAG213 with nfcpy
[Python] How to get divisors of natural numbers at high speed
How to check the memory size of a variable in Python
[Python] How to get the first and last days of the month
How to get a string from a command line argument in python
Here's a brief summary of how to get started with Django
How to check the memory size of a dictionary in Python
Hit the New Relic API in Python to get the server status
[TensorFlow 2] How to check the contents of Tensor in graph mode
How to create a large amount of test data in MySQL? ??
Python techniques for those who want to get rid of beginners