T
T
Telmor2021-09-29 09:26:12
Python
Telmor, 2021-09-29 09:26:12

How to work with discord.py cogs discord_components?

I have a code, and when I run it in cogs (all other cogs work fine), I get an error that the components argument does not exist (I double-checked everything).

The code:

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))

And here is the error:

Бот запущен
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'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zagir Majidov, 2021-09-29
@Zagir-vip

Hello, you are not correctly sending embed with components
. That's right:

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)

T
Telmor, 2021-09-29
@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

Here is the correct code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question