@Pavlosik

Как сделать /slash команды в боте на библеотеке discord.py?

Я хочу сделать слеш команды на своем боте но не как не могу пытался сделать так
Андрей Ульдин.slash(name = 'say', description = 'Говорить через бота', options = [{"name": "member", "description": "Говорить через ботика", "type": 6, "requied": False}], guild_ids = [864407095691968523]) но не получалсь
Помогите пж
вот мой код:
import discord
from discord.ext import commands
import os, sqlite3
import math
import random
from discord_components import DiscordComponents, Button, ButtonStyle
from asyncio import sleep
import time
from discord import Game
import requests
from discord import FFmpegPCMAudio
import youtube_dl
from os import system
from discord.utils import get
import asyncio
import voice
from discord import utils
import io
from config import settings

client = commands.Bot(command_prefix = settings['PREFIX'], intents=discord.Intents.all())
client.remove_command('help')

@client.event
async def on_ready():
    DiscordComponents(client)
    print('Ботяна на старте')

    await client.change_presence(status = discord.Status.online, activity = discord.Game('Python \n Создатель  Могучий#0464') )

    global base, cur
    base = sqlite3.connect('Ботяна.db')
    cur = base.cursor()
    if base:
        print('DataBase connected...OK') 


@client.event
async def on_command_error(ctx, error): #вывод ошибки при использавание команды
    pass


@client.command()
async def say(ctx, *, arg=None):
    author = ctx.message.author
    if arg == None:
         await ctx.send(f'{author.mention} Напишите /say текст')
    await ctx.send(arg) #/say


@client.command(aliases = ['mute', 'мут', 'заткнуть'])
async def __mute(ctx, member: discord.Member = None, amount_time = None, *, reason = None):
    if member is None:
        await ctx.send(embed = discord.Embed(
            title = f'{ctx.author.name}, **укажите пользователя**',
            description = f'Пример: .мут **@Участник** время причина'
        ))
    elif amount_time is None:
        await ctx.send(embed = discord.Embed(
            title = f'{ctx.author.name}, **укажите кол-во времени**',
            description = f'Пример: .mute @Участник **время** причина'
        ))
    elif reason is None:
        await ctx.send(embed = discord.Embed(
            title = f'{ctx.author.name}, **укажите причину**',
            description = f'Пример: .mute @Участник время **причина**'
        ))
    else:
        if 'm' in amount_time:
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Вы были замучены на **{amount_time}**.
                **Выдал мут:** {ctx.author.name}
                ```css
Причина: [{reason}]
                ```
                ''',
                color = 0x36393E,
            ))
 
            mute_role = discord.utils.get(ctx.guild.roles, id = 872516107687329812)
            await member.add_roles(mute_role)
            await asyncio.sleep(int(amount_time[:-1]) * 60)
            await member.remove_roles(mute_role)
 
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Время мута истекло, вы были размучены''',
                color = 0x2F3136
            ))  
        elif 'h' in amount_time:
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Вы были замучены на **{amount_time}**.
                **Выдал мут:** {ctx.author.name}
                ```css
Причина: [{reason}]
                ```
                ''',
                color = 0x36393E,
            ))
 
            mute_role = discord.utils.get(ctx.guild.roles, id = 872516107687329812)
            await member.add_roles(mute_role)
            await asyncio.sleep(int(amount_time[:-1]) * 60 * 60)
            await member.remove_roles(mute_role)
 
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Время мута истекло, вы были размучены''',
                color = 0x2F3136
            ))  
        elif 'd' in amount_time:
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Вы были замучены на **{amount_time}**.
                **Выдал мут:** {ctx.author.name}
                ```css
Причина: [{reason}]
                ```
                ''',
                color = 0x36393E,
            ))
 
            mute_role = discord.utils.get(ctx.guild, id = 872516107687329812)
            await member.add_roles(mute_role)
            await asyncio.sleep(int(amount_time[:-1]) * 60 * 60 * 24)
            await member.remove_roles(mute_role)
 
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Время мута истекло, вы были размучены''',
                color = 0x2F3136
            ))  
        else:
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Вы были замучены на **{amount_time}s**.
                **Выдал мут:** {ctx.author.name}
                ```css
Причина: [{reason}]
                ```
                ''',
                color = 0x36393E,
            ))
 
            mute_role = discord.utils.get(ctx.guild.roles, id = 872516107687329812)
            await member.add_roles(mute_role)
            await asyncio.sleep(int(amount_time))
            await member.remove_roles(mute_role)
 
            await ctx.send(embed = discord.Embed(
                description = f'''**[*]** Время мута истекло, вы были размучены''',
                color = 0x2F3136
            ))  

# Clear message
@client.command()
@commands.has_permissions( administrator = True )
 
async def clear( ctx, amount : int ):
    await ctx.channel.purge( limit = amount )
 
    await ctx.send(embed = discord.Embed(description = f':white_check_mark: Удалено {amount} сообщений', color=0x0c0c0c))

@client.command(aliases = ['шар'])
async def ball(ctx, *, question):
    await ctx.send(random.choice(['Да', 'Нет', 'Не думаю', 'Чуть-чуть', 'Отрицаю', 'Может быть!']))


  
@client.command
async def back(ctx):
    await ctx.send('Я вернулся')

client.run(settings['TOKEN'])
  • Вопрос задан
  • 1700 просмотров
Решения вопроса 1
Vindicar
@Vindicar
RTFM!
Никак. Разработка discord.py остановилась, и автор не стал добавлять slash команды. Используй другие либы.
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@Super_Games
в обновлении 2.0 это выглядит как то так
import discord
from discord.ext import commands
from discord import app_commands
from discord import utils


intents = discord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix='!', intents=intents)

class abot(discord.Client):
	def __init__(self):
		super().__init__(intents = discord.Intents.all())
		self.synced = False

	async def on_ready(self):
		await tree.sync(guild = discord.Object(id=айди сервера))
		self.synced = True
		print('Бот в сети')

client = abot()
tree = app_commands.CommandTree(bot)

@tree.command(name='название команды', description='описание команды', guild=discord.Object(id=айди сервера))
async def ping(interaction: discord.Interaction):
	await interaction.response.send_message('pong')

client.run(settings['TOKEN'])
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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