@GitRun

При вводе команды бот отправляет 2 сообщения. Как решить?

При вводе команды бот оправляет 2 сообщения, вместо 1

import discord
from discord.ext import commands
import datetime

client = commands.Bot( command_prefix = '*' )
client.remove_command( 'help' )

#########################################################################################################
hello_words = [ 'Hello', 'hi', 'привет', 'ку', 'q', 'qq', 'й', 'йй', 'privet', 'ky', 'ку', 'здарова' ]
answer_words = [ 'Узнать информацию о сервере', 'какая информация?',
				'cmd', 'команды', 'команды сервера', 'что здесь делать?' ]

goodbye_words = [ 'bb', 'пока', 'всем пока', 'b', 'bb all', 'poka', 'удачи всем', 'я ушел' ]
#########################################################################################################
@client.event

async def on_ready():
	print( 'Bot Started!' )

	await client.change_presence( status = discord.Status.idle, activity = discord.Game( 'ERROR | *help' ) )

############################

@client.event
async def on_command_error( ctx, error ):
	pass

#bot # # # # # # # # # # 
@client.event

async def on_member_join( member ):
	channel = client.get_channel( 755064800861487118 )

	role = discord.utils.get( member.guild.roles, id = 755068818556059730 )

	await member.add_roles( role )
	await channel.send( embed = discord.Embed( description = f'Пользователь ``{ member.name }``, присоеденился к нам!' ) )	

#######################################################################################
# токен
@client.event

async def on_message( message ):
	msg = message.content.lower()
	await client.process_commands( message )

	if msg in hello_words:
		await message.channel.send( 'Привет, как дела?' )

	if msg in answer_words:
		await message.channel.send( 'Пропиши в чат команду *help, и все узнаешь!' )

	if msg in goodbye_words:
		await message.channel.send( 'Желаю удачи.' )

########################################################
# Kick
	await client.process_commands( message )
@client.command( pass_context = True )
@commands.has_permissions( administrator = True )

async def kick( ctx, member: discord.Member, *, reason = None ):
	await ctx.channel.purge( limit = 1 )

	await member.kick( reason = reason )
	await ctx.send( f' Был кикнут --> { member.mention }' )
########################################################
# Ban
	await client.process_commands( message )
@client.command( pass_context = True )
@commands.has_permissions( administrator = True )

async def ban( ctx, member: discord.Member, *, reason = None ):
	emb = discord.Embed( title = 'Ban', colour = discord.Color.red() )
	await ctx.channel.purge( limit = 1 )

	await member.ban( reason = reason )

	emb.set_author( name = member.name, icon_url = member.avatar_url )
	emb.add_field( name = ' Ban User ', value = ' Пользователь был забанен!  : {}'.format( member.mention ) )
	emb.set_footer( text = 'Был забанен администратором {}'.format( ctx.author.name ), icon_url = ctx.author.avatar_url )
	emb.set_thumbnail( url = 'https://www.pngkey.com/png/full/218-2184733_png-royalty-free-banned-png-for-free-download.png' )

	await ctx.send( embed = emb )

	#await ctx.send( f' Был забанен --> { member.mention }' )
#####################################################
# Unban
	await client.process_commands( message )
@client.command( pass_context = True )

async def unban( ctx, *, member ):
	await ctx.channel.purge( limit = 1 )

	banned_users = await ctx.guild.bans()

	for ban_entry in banned_users:
		user = ban_entry.user

		await ctx.guild.unban( user )
		await ctx.send( f' Пользователь был разбанен! --> { user.mention }' )

		return

# command help
	await client.process_commands( message )
@client.command()
@commands.has_permissions( administrator = True )

async def help( ctx ):
	emb = discord.Embed( title = 'Навигация по командам', colour = discord.Color.purple() )

	emb.add_field( name = '{}clear'.format( '*' ), value = 'Очистка чата (кол-во сообщений)' )
	emb.add_field( name = '{}kick'.format( '*' ), value = 'Удаление участника' )
	emb.add_field( name = '{}ban'.format( '*' ), value = 'Ограничение доступа к серверу' )
	emb.add_field( name = '{}unban'.format( '*' ), value = 'Разбан нарушителя' )
	emb.add_field( name = '{}mute'.format( '*' ), value = 'Ограничение доступа к чату/голосовому чату' )

	await ctx.send( embed = emb )

####################################################
@client.command( pass_context = True )

async def time( ctx ):
	emb = discord.Embed( title = '⌚️ Точное время (МСК)', description = 'Вы можете узнать текущее время', colour = discord.Color.purple(), url = 'https://time100.ru' )

	emb.set_author( name = client.user.name, icon_url = client.user.avatar_url )
	emb.set_footer( text = 'Спасибо за использование нашего бота!', icon_url = ctx.author.avatar_url )
	#emb.set_image( url = 'https://www.thehomewarescompany.com/media/catalog/product/cache/1/thumbnail/1800x1800/17f82f742ffe127f42dca9de82fb58b1/k/a/ka4922_1.jpg' )
	emb.set_thumbnail( url = 'https://www.thehomewarescompany.com/media/catalog/product/cache/1/thumbnail/1800x1800/17f82f742ffe127f42dca9de82fb58b1/k/a/ka4922_1.jpg' )

	now_date = datetime.datetime.now(  )

	emb.add_field( name = 'Time', value = '⌚️ Время --> : {}'.format( now_date ) )

	await ctx.author.send( embed = emb )

#mute

	await client.process_commands( message )
@client.command()
@commands.has_permissions( administrator = True )

async def mute( ctx, member: discord.Member ):
	await ctx.channel.purge( limit = 1 )

	mute_role = discord.utils.get( ctx.message.guild.roles, name = 'mute' )

	await member.add_roles( mute_role )
	await ctx.send( f'У { member.mention }, ограничение чата, за нарушение прав!'  )

#####################################################
# очистка
	await client.process_commands( message )
@client.command( pass_context = True )
@commands.has_permissions( administrator = True )

async def clear( ctx, amount : int ):
	await ctx.channel.purge( limit = amount )
#
#####################################################
# очистка команд

	await client.process_commands( message )
@client.command( pass_context = True )

async def hello( ctx, amount = 1 ):
	await ctx.channel.purge( limit = amount )

	author = ctx.message.author
	await ctx.send( f'Привет! { author.mention }' )
#####################################################

@client.command()
async def send_a( ctx ):
	await ctx.author.send ( 'Привет!' )

@client.command()
async def send_m( ctx, member: discord.Member ):
	await member.send( f"{ member.name }, привет от { ctx.author.name }" )

########

@clear.error
async def clear_error( ctx, error ):
	if isinstance( error, commands.MissingRequiredArgument ):
		await ctx.send( f'{ ctx.author.name }, вы не указали аргумент!, если вы хотите очистить чат полность напишите ''*clearchat' )

	if isinstance( error, commands.MissingPermissions ):
		await ctx.send( f'{ ctx.author.name }, у вас недостаточно прав!' )

#####################################################
# Connect
token = open( 'token.txt', 'r' ).readline()

client.run( token )
#####################################################

А вот сам код команды | help
async def help( ctx ):
	emb = discord.Embed( title = 'Навигация по командам', colour = discord.Color.purple() )

	emb.add_field( name = '{}clear'.format( '*' ), value = 'Очистка чата (кол-во сообщений)' )
	emb.add_field( name = '{}kick'.format( '*' ), value = 'Удаление участника' )
	emb.add_field( name = '{}ban'.format( '*' ), value = 'Ограничение доступа к серверу' )
	emb.add_field( name = '{}unban'.format( '*' ), value = 'Разбан нарушителя' )
	emb.add_field( name = '{}mute'.format( '*' ), value = 'Ограничение доступа к чату/голосовому чату' )

	await ctx.send( embed = emb )
  • Вопрос задан
  • 755 просмотров
Пригласить эксперта
Ответы на вопрос 2
У вас метод обработки команд (process_commands) в on_message вызывается дважды
Ответ написан
Комментировать
@demon666top
у тебя написано 2 одинаковых кодов help проверь код
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы