Issue
I made a rickroll detector but it needs to check if the message (defined as i) contains a word/text from the "banned" list.
Code:
import discord
from discord.ext import commands
from async_rickroll_detector import RickRollDetector
banned = []
banned = ["dQw4w9WgXcQ, rW7hXs-81hM"]
BOT_TOKEN = "<TOKEN>"
RICKROLL_FOUND_MESSAGE = "⚠️ Rickroll Alert ⚠️"
bot = commands.Bot(command_prefix = ">", intents = discord.Intents.default())
@bot.event
async def on_ready():
global detector
detector = RickRollDetector()
@bot.event
async def on_message(msg):
for i in msg.content.split(" "):
i = i.replace("<","").replace(">", "") #Removes <> that could be used to hide embeds
if banned in i and await detector.find(i):
await msg.reply(RICKROLL_FOUND_MESSAGE)
break
await bot.process_commands(msg)
bot.run(BOT_TOKEN)
I'll add more things to the "banned" list so this is just a test.
Solution
A better way to this is use any().
@bot.event
async def on_message(msg):
if any(x in msg.content for x in banned):
await msg.reply(RICKROLL_FOUND_MESSAGE)
And you don't need to use break and it is cleaner. :)
Answered By - MatiYo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.