-1

A lot of people in discord servers send these emoji spam things, and I'm trying to keep it down. I'd like to delete any messages with more than 7 emojis. How can I do this? Something along the lines of:

@client.event
async def on_message(message):
 if more than 5 emojis in message.content and message.channel.id == 717525332093042808 and message.channel.id == 723147921264082974:

I also have 2 channels I'd like to delete this from. Does message.channel.id == 717525332093042808 and message.channel.id == 723147921264082974 solve the problem?

  • For the second part of your question: **No**. If you do that, it will always be `False`. You need an `or`: `if id == 1 or id == 2` – Asocia Jun 21 '20 at 20:33
  • And for the first part of your question, take a look at [this question](https://stackoverflow.com/questions/43146528/how-to-extract-all-the-emojis-from-text/43146653). – jmkjaer Jun 21 '20 at 20:36
  • @jmkjaer sorry I don't get what i'm doing here –  Jun 21 '20 at 20:45
  • Which part exactly of determining whether there are more than 7 emojis in a message are you having difficulty with? Do you know how to determine whether there is *any* emoji in a message? – mkrieger1 Jun 21 '20 at 20:49
  • @mkrieger1 I don't understand how to determine whether or not there are more than 7 emojis in a message. –  Jun 21 '20 at 20:53
  • What about 1 emoji? – mkrieger1 Jun 21 '20 at 20:56
  • @mkrieger1 not that either –  Jun 21 '20 at 21:00
  • @iCrySam Did you take a look at the question (and two answers to it) I linked? What do you have problems with, specifically? The answers describe how to extract emoji from a string. You can add them to a list and check the length of the list. – jmkjaer Jun 21 '20 at 21:02
  • The other question linked in a comment above seems to have answers that explain everything there is to know about determining all the emojis contained in a string. What was the problem when you tried to apply that? – mkrieger1 Jun 21 '20 at 21:03
  • Yeah I read it. I don't understand how to use the string. Sorry, I'm really new to python. –  Jun 21 '20 at 21:07
  • @iCrySam What do you mean, "how to use the string"? We can't help you if you don't provide specific information about your problem. If you don't understand strings, I suggest you go through a Python tutorial [like this one](https://docs.python.org/3/tutorial/). – jmkjaer Jun 21 '20 at 21:12
  • @jmkjaer Sorry for not being specific. I'm trying to say I don't understand why I need to extract the emoji, and how I do it. I'd like to be able to delete all messages with more than 7 emojis. I'm assuming it would have to do with on_message. –  Jun 21 '20 at 21:26

1 Answers1

0

So I'm going to assume that you want a message to be deleted if it:

  1. Appears in these channels (717525332093042808 and 723147921264082974) AND
  2. Contains more than 7 emojis

For this issue you can use the re module, which is regex. I'm unsure about the regular emojis, but for server custom emojis you can do:

@client.event()
async def on_message(message):
    custom_emojis = re.findall(r'<:\w*:\d*>', message.content)
    if len(custom_emojis) > 7 and (message.channel.id == 717525332093042808 or message.channel.id == 723147921264082974):
        await message.delete()
Kelo
  • 1,783
  • 2
  • 9
  • 21
  • Yeah, thanks for the answer, but I wanted to know for the regular emojis. That answer does give me a step forward though. –  Jun 22 '20 at 01:00
  • You might be able to use regex again, but try to detect the regular emojis through their unicode similarities. – Kelo Jun 22 '20 at 01:15