Этот вопрос закрыт для ответов, так как повторяет вопрос Как сделать slash команды в когах discord.py?
@Telmor

Как работать с когами discord.py discord_components?

У меня есть код, и когда я его запускаю в когах (все остальные коги работают нормально), то выдаётся ошибка, что не существует аргумента components (всё перепроверял).

Код:

import discord
from discord import guild
from discord import embeds
from discord import emoji
from discord.embeds import Embed
from discord.ext import commands
from discord.ext.commands import Bot
from discord import member
import asyncio
import os
import string
import json
from discord import Activity, ActivityType
from discord.utils import *
import io
import time
import string
from discord_components import *
from dislash import *
import requests
import random
import re

class User(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    def __init__(self, bot):
        self.bot = bot
    
    test_guilds = [838669514904043550]

    @commands.command()
    async def create_event(self, ctx, arg):
        channel = self.bot.get_channel(889181835010117652)
        channel2 = ctx.author.voice.channel.id
        emb = discord.Embed(title='Ивенты', description=f'Выберите ивент который хотите провести.')
        emb.set_thumbnail(url=ctx.author.avatar_url)
        msg = await ctx.send(embed = emb,
            components=[
                Button(style=ButtonStyle.gray, label='CodeNames', emoji=''),
                Button(style=ButtonStyle.gray, label='Бункер', emoji=''),
                Button(style=ButtonStyle.gray, label='Дурак Онлайн', emoji=''),
                Button(style=ButtonStyle.gray, label='Шляпа', emoji=''),
                Button(style=ButtonStyle.gray, label='Сломанный телефон', emoji='')
            ])
        responce = await self.bot.wait_for('button_click', check=lambda message: message.author == ctx.author)
        if responce.component.label == 'CodeNames':
            emb = discord.Embed(title='CodeNames', description=f'Ивент CodeNames. Проводит:{ctx.author.mention}\n Когда: {arg} \n Где: <#{channel2}>')
            await channel.send(embed = emb, components=[])
            maincategory = discord.utils.get(guild.categories, id=885951526194008094)#id категории где будет создаваться канал
            channel2 = await guild.create_voice_channel(name=f'Ивент CodeNames',category = maincategory)
            await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
            await member.move_to(channel2)
            emb = discord.Embed(title='Закончить Ивент', description=f'{ctx.author.mention}, для завершения ивента нажмите кнопку ниже.')
            await ctx.send(embed = emb, components=[Button(style=ButtonStyle.red, label='Закончить Ивент', emoji='❌')])
            responce = await self.bot.wait_for('button_click', check=lambda message: message.author == ctx.author)
            if responce.component.label == 'Закончить Ивент':
                emb = discord.Embed(title='Окончание Ивента', description=f'{ctx.author.mention}, вы завершили ивент CodeNames')
                await ctx.send(embed = emb, components=[])
                await channel2.delete()
        if responce.component.label == 'Бункер':
            emb = discord.Embed(title='Бункер', description=f'Ивент Бункер. Проводит:{ctx.author.mention}\n Когда: {arg} \n Где: <#{channel2}>')
            await channel.send(embed = emb, components=[])
            maincategory = discord.utils.get(guild.categories, id=885951526194008094)#id категории где будет создаваться канал
            channel2 = await guild.create_voice_channel(name=f'Бункер',category = maincategory)
            await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
            await member.move_to(channel2)
        if responce.component.label == 'Дурак Онлайн':
            emb = discord.Embed(title='Дурак Онлайн', description=f'Ивент Дурак Онлайн. Проводит:{ctx.author.mention}\n Когда: {arg} \n Где: <#{channel2}>')
            await channel.send(embed = emb, components=[])
            maincategory = discord.utils.get(guild.categories, id=885951526194008094)#id категории где будет создаваться канал
            channel2 = await guild.create_voice_channel(name=f'Дурак Онлайн',category = maincategory)
            await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
            await member.move_to(channel2)
        if responce.component.label == 'Шляпа':
            emb = discord.Embed(title='Шляпа', description=f'Ивент Шляпа. Проводит:{ctx.author.mention}\n Когда: {arg} \n Где: <#{channel2}>')
            await channel.send(embed = emb, components=[])
            maincategory = discord.utils.get(guild.categories, id=885951526194008094)#id категории где будет создаваться канал
            channel2 = await guild.create_voice_channel(name=f'Шляпа',category = maincategory)
            await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
            await member.move_to(channel2)
        if responce.component.label == 'Сломанный телефон':
            emb = discord.Embed(title='Сломанный телефон', description=f'Ивент Сломанный телефон. Проводит:{ctx.author.mention}\n Когда: {arg} \n Где: <#{channel2}>')
            await channel.send(embed = emb, components=[])
            maincategory = discord.utils.get(guild.categories, id=885951526194008094)#id категории где будет создаваться канал
            channel2 = await guild.create_voice_channel(name=f'Сломанный телефон',category = maincategory)
            await channel2.set_permissions(member,connect=True,mute_members=True,move_members=True,manage_channels=True)
            await member.move_to(channel2)

    
def setup(bot):
    bot.add_cog(User(bot))

А вот ошибка:

Бот запущен
Ignoring exception in command create_event:
Traceback (most recent call last):
  File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\Fenix\Desktop\MainBots\cogs\ticket.py", line 40, in create_event
    msg = await ctx.send(embed = emb,
TypeError: send() got an unexpected keyword argument 'components'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: send() got an unexpected keyword argument 'components'
  • Вопрос задан
  • 1248 просмотров
Ответы на вопрос 2
Zagir-vip
@Zagir-vip
Web dev, Game dev, app dev, Разработчик на Python!
Здраствуйте вы не правильно отправляете embed с components

Вот правильно:

emb = discord.Embed(title='Ивенты', description=f'Выберите ивент который хотите провести.', 
  components=[
                Button(style=ButtonStyle.gray, label='CodeNames', emoji=''),
                Button(style=ButtonStyle.gray, label='Бункер', emoji=''),
                Button(style=ButtonStyle.gray, label='Дурак Онлайн', emoji=''),
                Button(style=ButtonStyle.gray, label='Шляпа', emoji=''),
                Button(style=ButtonStyle.gray, label='Сломанный телефон', emoji='')
            ])
        emb.set_thumbnail(url=ctx.author.avatar_url)
        msg = await ctx.send(embed = emb)
Ответ написан
@Telmor Автор вопроса
@commands.command()
    async def create_event(self, ctx, arg):
        #channel = self.bot.get_channel(889181835010117652)
        #channel2 = ctx.author.voice.channel.id
        emb = discord.Embed(title='Ивенты', description=f'Выберите ивент который хотите провести')
        emb.set_thumbnail(url=ctx.author.avatar_url)
        msg = await ctx.send(embed = emb,
        components=[
                [
                Button(style=ButtonStyle.gray, label='CodeNames', emoji='', custom_id = 'CodeNames'),
                Button(style=ButtonStyle.gray, label='Бункер', emoji='',custom_id = 'Бункер'),
                Button(style=ButtonStyle.gray, label='Дурак Онлайн', emoji='',custom_id = 'Дурак Онлайн'),
                Button(style=ButtonStyle.gray, label='Шляпа', emoji='',custom_id = 'Шляпа'),
                Button(style=ButtonStyle.gray, label='Сломанный телефон', emoji='',custom_id = 'Сломанный телефон')
                ]
            ])
        
        responce = await self.bot.wait_for('button_click', check=lambda message: message.author == ctx.author)
        member = ctx.author

Вот правильный Код.
Ответ написан
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы