How to start function from another function

  discord, discord.py, python-3.x

I have made a function to help users type commands. It helps with mistakes. After finding mistakes user must input 1 or 2 or 3 (command that he wanted to use).


import asyncio

@bot.event
async def on_command_error(self, ctx, error):
  global list_command
  tmp_prefix = settings['prefix']
  if isinstance(error, discord.ext.commands.errors.CommandNotFound):
    content = ctx.message.content.split()[0].replace(settings['prefix'], '')
    args = ctx.message.content.replace(f'{tmp_prefix}{content} ', '')
    list = [str(x) for x in content]
    mx = 0
    mx_command_1 = ''
    mx_command_2 = ''
    mx_command_3 = ''
    for command in list_command:
      mx_tmp = 0
      # print(f'command = {command}')
      for symbol in list:
        if symbol in command:
          # print(f'symbol = {symbol}')
          mx_tmp += 1 
      if mx_tmp >= mx:
        mx_command_3 = mx_command_2
        mx_command_2 = mx_command_1
        mx = mx_tmp
        mx_command_1 = command
      # print(f'mx {mx}')
    await ctx.channel.purge(limit = 1)
    if mx_command_1 != '' and mx_command_2 != '':
      emb = discord.Embed(title = f'Did you mean these commands instead of ``{ctx.message.content.split()[0]}``')
    else:
      emb = discord.Embed(title = f'Did you mean this command instead of ``{ctx.message.content.split()[0]}``')
    if mx_command_1 != '' and mx_command_2 == '' and mx_command_3 == '':
      emb.add_field(name = f'1 - {tmp_prefix}{mx_command_1}', value = 'Type $1')
      await ctx.channel.send(embed = emb)
    elif mx_command_1 != '' and mx_command_2 != '' and mx_command_3 == '':
      emb.add_field(name = f'1 - {tmp_prefix}{mx_command_1}', value = 'Type 1')
      emb.add_field(name = f'2 - {tmp_prefix}{mx_command_2}', value = 'Type 2')
      await ctx.channel.send(embed = emb)
    elif mx_command_1 != '' and mx_command_2 != '' and mx_command_3 != '':
      emb.add_field(name = f'1 - {tmp_prefix}{mx_command_1}', value = 'Type 1')
      emb.add_field(name = f'2 - {tmp_prefix}{mx_command_2}', value = 'Type 2')
      emb.add_field(name = f'2 - {tmp_prefix}{mx_command_3}', value = 'Type 3')
      await ctx.channel.send(embed = emb)
    else:
      await ctx.channel.send(embed = discord.Embed(description = 'No such command exists!', color = settings['admin_color']), delete_after = 5)
    
    def check(m: discord.Message):
        return m.author.id == ctx.message.author.id and m.channel.id == ctx.channel.id and (m.content == '1' or m.content == '2' or m.content == '3')
    try:
        msg = await bot.wait_for(event = 'message', check = check, timeout = 10.0)
    except asyncio.TimeoutError:
        await ctx.channel.purge(limit = 1)
    else:
        if args = '':
            if msg.content == '1':
                await ctx.invoke(self.bot.get_command(mx_command_1), ctx = ctx)
            elif msg.content == '2':
                await ctx.invoke(self.bot.get_command(mx_command_2), ctx = ctx)
            else:
                await ctx.invoke(self.bot.get_command(mx_command_3), ctx = ctx) #here I need to invoke
    

I want my bot to remember arguments from user request. Arguments are kept in string args. Can I start function that user wants and use args string as arguments for it?

Source: Python-3x Questions

LEAVE A COMMENT