Search code examples
pythondiscorddiscord.pycommandbots

The command of my bot in the Discard is not displayed when entering /


When I start typing / then my bot is not in the built-in commands (usually bots appear and a list of all their commands is visible)...

I have hidden parts of the text with ____ signs in order not to distract from the main code. I am new to this business, so I will be glad of any comments and advice :) Thank you all in advance for the answers

import os
import discord
import asyncio
import aiohttp
from discord.ext import commands
from discord.ui import View, Button
import interactions

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='/', intents=intents, case_insensitive=True)

@bot.command(name='wew')
async def wew_command(ctx):
    pass
@bot.event
async def on_message(message):
    if message.author != bot.user and message.content.startswith('/wew'):
        user_input = message.content[len('/wew'):].strip()
        lines = user_input.split(',')
        if len(lines) == 6:
          block_title = "№ " + lines[0].strip()`
          embed = discord.Embed(title=block_title, color=0x000000)
          if lines[1].isnumeric():
            mention = lines[1]

          else:
            user_id = lines[1].strip().strip('<@!>').strip('<@').strip('>')
            mentioned_user = await bot.fetch_user(user_id)
            if mentioned_user:
                mention = mentioned_user.mention

            else:
                mention = f"<@{user_id}>"
          field_value = f"**1. _____________ {mention}**"
          embed.add_field(name="\u200B", value=field_value, inline=False)
          embed.add_field(name="**_________** " + lines[2], value="", inline=False)
          embed.add_field(name="**_________** " + lines[3], value="", inline=False)
          embed.add_field(name="**_________** " + lines[4], value="", inline=False)
          embed.add_field(name="**_________** " + lines[5], value="", inline=False)
          embed.add_field(name="\u200B", value="**_________** " + message.author.mention)
          await message.channel.send(embed=embed)
          await message.delete()

        else:
          embed = discord.Embed(title="Ошибка", description=f"_________, {message.author.mention}, _________*", color=discord.Color.red())

          await message.reply(embed=embed, delete_after=5)

          await message.delete()
token = '_______'
keep_alive()
bot.run(token)

P.S. the team is working well


Solution

  • If you are using discord.py then you need to create and sync tree commands. Here is how:

    Sync the tree:

    @bot.command()
    async def treesync(ctx:commands.Context):
        synced = await bot.tree.sync()
        await ctx.send(f"Synced {len(synced)} commands")
    

    Create a simple tree command:

    @bot.tree.command(name="test3")
    async def test3(interaction:discord.Interaction,message:str):
        await interaction.response.send_message(f"Message: {message}",ephemeral=True)
        await interaction.edit_original_response(content="Hello!")
        asd:discord.Message = await interaction.followup.send("Hi!")
        await interaction.delete_original_response()
        await interaction.followup.delete_message(asd.id)
    

    These are the main things you will need with slash commands. You can also sync in your on_ready functions. (I do that too but Stack users hate it :D) It uses more requests but if you are just messing around and testing with bots than it is easier.