Answer the question
In order to leave comments, you need to log in
How to make /slash commands in a bot on the discord.py library?
I want to make a slash command on my bot, but I can't do it like this
Andrey Uldin .slash(name = 'say', description = 'Speak through the bot', options = [{"name": "member", "description" : "Speak through the boat", "type": 6, "requied": False}], guild_ids = [864407095691968523]) but didn't work
Please help me
here is my code:
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'])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question