Skip to content
Advertisement

Bot will not log an automod event if user has blocked the bot

If someone says a bad word that triggers the automod, the bot will delete the message, DM the user, and log it in a log channel.

The problem is if someone blocks the bot and says a bad word, the bot can’t DM the user which doesn’t allow the bot to log the event in a log channel.

I tried multiple ways to fix this by adding if and else and except but those do not help. Below is the current code that I have already, so how can I make the bot still log the event if the offender has blocked the bot?

JavaScript

Advertisement

Answer

Try/except

When you have a try/except in your code, Python will try to execute the code, and if there is and error he will execute the code in the except section. So a code in the try section may be not executed.

What in your code needs a try/except ?

In your code, the things which could raise an error are :

JavaScript

Which means that if there is an error on the first possibility, all the following code in the try will not be executed.

Solution

I advise you to have two try/except, the first for the DM, and the second for the log. You code with my solution is now :

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement