O
O
omgwhoit2020-12-06 16:06:38
Python
omgwhoit, 2020-12-06 16:06:38

How to make functions work together with discord.py?

If you send a message to the channel, then the bot will give a reaction, but !clear does not work

@bot.command(pass_context=True)
async def clear(ctx, arg):
  await ctx.message.delete()
  
  async for msg in ctx.message.channel.history(limit=int(arg)):
    if msg is not None:
      await msg.delete()
    
  embed = discord.Embed(title="Удалено "+str(arg)+" сообщений!", description="", color=0x00ff00)
  new_message = await ctx.send(embed=embed)
  await asyncio.sleep(5)
  await new_message.delete()

@bot.event
async def on_message(message):
  suggestion_channel_id = 782338760275918849
  if message.channel.id == suggestion_channel_id:
    if message.content.startswith('!'):
        pass
    else:
      await message.add_reaction("")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Amoralny, 2020-12-06
@omgwhoit

You need to get the Context Then you need to invoke CTRL+C
ctx = await bot.get_context(message)

await bot.invoke(ctx)

@bot.event
async def on_message(message):
  ctx = await bot.get_context(message)
  await bot.invoke(ctx)

Then the commands will work
ps. in on_message() it is better not to set command processing, for this there is @bot.command

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question