A
A
AleXAndR1692021-10-27 15:07:58
Python
AleXAndR169, 2021-10-27 15:07:58

If there is @bot.event in the code, @bot.commands does not work (done on python 3.9). What to do?

import discord 
from discord.ext import commands 

bot = commands.Bot(command_prefix = ".", intents = discord.Intents.all())

@bot.event
async def on_message(message):
  if 'smetanka_v_dele' in message.content.lower():
    await message.channel.send('хозяин занят')
    await bot.process_commands(message)
    
@bot.event
async def on_ready():
  await bot.change_presence(status=discord.Status.idle, activity=discord.Game('SCP secret labaratory'))
  print("I am connected, my lord!")

@bot.event

async def on_member_join( member ):
  channel = bot.get_channel( 888164664012328991 )

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

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

@bot.event
async def on_message_delete(message):
  channel = bot.get_channel(888164664012328991)
  embed = discord.Embed(title = f"Пользователь удалил сообщение {message.content}", description = f"Канал: {message.channel.mention}")
  await channel.send(embed = embed)
  await bot.process_commands(message)

@bot.event
async def on_message_edit(before, after):
  if before.content == after.content:
    return
  await before.channel.send(f"Сообщение было изменено!\n{before.content} -> {after.content}")
  await bot.process_commands(message)

@bot.event
async def on_voice_state_update(member, before, after):
  if before.channel == after.channel:
    return
  if not before.channel:
    channel = bot.get_channel( 888164664012328991 )
    embed = discord.Embed(title = f"Пользователь {member.name} зашёл в голосовой канал", description = f"Канал: {after.channel.mention}", color  = member.color)
    return await channel.send(embed = embed)

  if not after.channel:
    channel = bot.get_channel( 888164664012328991 )
    embed = discord.Embed(title = f"Пользователь {member.name} вышел из голосового канала", description = f"Канал: {before.channel.mention}", color  = member.color)
    return await channel.send(embed = embed)
  else:
    channel = bot.get_channel( 888164664012328991 )
    embed = discord.Embed(title = f"Пользователь {member.name} перешёл в голосовой канал", description = f"Канал до: {before.channel.mention}\nКанал после {after.channel.mention}", color  = member.color)
    return await channel.send(embed = embed)

@bot.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)

@bot.command( pass_context = True )
@commands.has_permissions( administrator = True )	

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

  await member.ban(reason = reason)
  await ctx.send(f'ban user { member.mention }')

@bot.command()
async def морковка(ctx):
  await ctx.send('нет, это картошка')

@bot.command( pass_context = True )

async def clear( ctx, amount = 100 ):
  await ctx.channel.purge( limit = amount )

bot.run("token")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-10-27
@AleXAndR169

This is how it should be as written. The call to bot.process_commands(message) only happens when the message contains a smetanka_v_dele. Remove process_commands from if.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question