Почему-то не работает, бот включается, но банворды не удаляет

Рейтинг: 0Ответов: 1Опубликовано: 27.03.2023
import disnake
from disnake.ext import commands

bot = commands.Bot(command_prefix="*", help_command=None, intents=disnake.Intents.all())


@bot.event
async def on_ready():
    print(f"Bot {bot.user} is ready to work!")


with open('bun_words.txt', 'r', encoding='utf8') as file:
    kek = file.read()

@bot.event
async def on_message(message):
    for content in message.content.split():
        for censored_word in kek:
            if content == censored_word:
                await message.delete()
                await message.channel.send(f"{message.author.mention} такие слова запрещены!")


@bot.event
async def on_commands_error(ctx, error):
    print(error)

bot.run()

Ответы

▲ 0

можно использовать метод readlines() чтобы построчно грузить файл

import disnake
from disnake.ext import commands

bot = commands.Bot(command_prefix="*", help_command=None, intents=disnake.Intents.all())


@bot.event
async def on_ready():
    print(f"Bot {bot.user} is ready to work!")


with open('bun_words.txt', 'r', encoding='utf8') as file:
    kek = [word.strip() for word in file.readlines()]

@bot.event
async def on_message(message):
    for content in message.content.split():
        for censored_word in kek:
            if content == censored_word:
                await message.delete()
                await message.channel.send(f"{message.author.mention} такие слова запрещены!")


@bot.event
async def on_commands_error(ctx, error):
    print(error)

bot.run()