2
import discord
import os
import datetime
from discord.ext import commands, tasks
from discord.ext.commands import Bot
from discord import Embed
from discord_components import DiscordComponents, Button
import time
import re
import json
from urllib import parse, request
import random
import sys
import traceback
from discord import Game
from asyncio import sleep
import asyncio
from discord.ext import commands
from config import settings
import requests

bot = commands.Bot(command_prefix='.')
bot.remove_command('help')

os.system('clear')


@bot.event
async def on_message(message):
    if message.content == "Всем привет":
        await message.channel.send("привет!")
        await bot.process_commands(message)`введите сюда код`


@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

ban_words = ['ука', 'бя', 'ебть', 'науй', 'иди нуй', 'бдь', 'бть', 'пола науй', 'суа', 'шха', 'тпа', 'хй', 'чен']

def simplify_word(word):
    last_letter = ''
    result = ''
    for letter in word:
        if letter != last_letter:
            last_letter = letter
            result += letter
    
    return result

@bot.event
async def on_message(message):
    if message.author.bot:
        return

    msg_words = [simplify_word(word) for word in message.content.split()]

    
    for word in msg_words:
        if word in ban_words:
            try:
                await message.delete()
            except:
                print('Ошибка при удалении сообщения')
            await message.channel.send(f'{message.author.mention} **маты не писать!**')
            return
    await bot.process_commands(message)



@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='PonHub'))
    
    print('Бот Love<3 онлайн')
    print(bot.user.name)
    print('-----------')
    name = input("Введите ваше имя: ")
    print(f" Приветик папочка~ мурр)")
    print('-----------')
    print ("""\
    
    
██╗░░░░░░█████╗░██╗░░░██╗███████╗
██║░░░░░██╔══██╗██║░░░██║██╔════╝
██║░░░░░██║░░██║╚██╗░██╔╝█████╗░░
██║░░░░░██║░░██║░╚████╔╝░██╔══╝░░
███████╗╚█████╔╝░░╚██╔╝░░███████╗
╚══════╝░╚════╝░░░░╚═╝░░░╚══════╝

""")


bot.run(settings['token'])

Перестаёт работать весь код когда я добавляю сверху:

@bot.event
async def on_message(message):
    if message.content == "Всем привет":
        await message.channel.send("привет!")
        await bot.process_commands(message)

1 ответ 1

3

У вас повторяется функция on_message, нужно объединить их

import discord
import os
import datetime
from discord.ext import commands, tasks
from discord.ext.commands import Bot
from discord import Embed
from discord_components import DiscordComponents, Button
import time
import re
import json
from urllib import parse, request
import random
import sys
import traceback
from discord import Game
from asyncio import sleep
import asyncio
from discord.ext import commands
from config import settings
import requests

bot = commands.Bot(command_prefix='.')
bot.remove_command('help')

os.system('clear')

@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

ban_words = ['ука', 'бя', 'ебть', 'науй', 'иди нуй', 'бдь', 'бть', 'пола науй', 'суа', 'шха', 'тпа', 'хй', 'чен']

def simplify_word(word):
    last_letter = ''
    result = ''
    for letter in word:
        if letter != last_letter:
            last_letter = letter
            result += letter
    
    return result

@bot.event
async def on_message(message):
    if message.author.bot:
        return

    if message.content == "Всем привет":
        await message.channel.send("привет!")

    msg_words = [simplify_word(word) for word in message.content.split()]

    
    for word in msg_words:
        if word in ban_words:
            try:
                await message.delete()
            except:
                print('Ошибка при удалении сообщения')
            await message.channel.send(f'{message.author.mention} **маты не писать!**')
            return
    await bot.process_commands(message)



@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='PonHub'))
    
    print('Бот Love<3 онлайн')
    print(bot.user.name)
    print('-----------')
    name = input("Введите ваше имя: ")
    print(f" Приветик папочка~ мурр)")
    print('-----------')
    print ("""\
    
    
██╗░░░░░░█████╗░██╗░░░██╗███████╗
██║░░░░░██╔══██╗██║░░░██║██╔════╝
██║░░░░░██║░░██║╚██╗░██╔╝█████╗░░
██║░░░░░██║░░██║░╚████╔╝░██╔══╝░░
███████╗╚█████╔╝░░╚██╔╝░░███████╗
╚══════╝░╚════╝░░░░╚═╝░░░╚══════╝

""")


bot.run(settings['token'])

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.