Closed FeelsBadMan1 closed 3 years ago
Send an empty message before the actual message with components.
Get the ctx from the empty message you sent, and use it to send your actual message with your components.
msg = await ctx.send("") #Send the empty message
ctx = await client.get_context(msg) #Get the Context(ctx) from it
em= Embed(title= "Muted Users", description= final_list, color= 0xFF5BF8)
await ctx.send(embed= em, components=[ #Use the ctx that you got from the empty message.
Button(label= "Unmute All", style=4, id="clear_muted_button"),
])
@FeelsBadMan1 Hello, I wrote the example cog. You are using slash context not discord context which is what we hook into at the end, I don't know if you are trying to use slash commands But I'm pretty sure slash commands don't support buttons. If they do try using DiscordComponents(slash)
rather than DiscordComponents(bot)
!
Hello, I tried both versions. on the version from @Shaqalito it print me following issure:
An exception has occurred while executing command `button`:
Traceback (most recent call last):
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord_slash\client.py", line 744, in invoke_command
await coro
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord_slash\model.py", line 227, in invoke
return await self.func(self.cog, *args, **kwargs)
File "D:\my_python_projects\MongoDB Test\Cogs\music.py", line 540, in buttontest
ctx = await bot.get_context(msg) # Get the Context(ctx) from it
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord\ext\commands\bot.py", line 883, in get_context
if self._skip_check(message.author.id, self.user.id):
AttributeError: 'NoneType' object has no attribute 'id'
on the second version from @PythonSerious follwoing error is being raised:
An exception has occurred while executing command `button`:
Traceback (most recent call last):
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord_slash\client.py", line 744, in invoke_command
await coro
File "D:\Downloads\Python\python 3.8.7\lib\site-packages\discord_slash\model.py", line 227, in invoke
return await self.func(self.cog, *args, **kwargs)
File "D:\my_python_projects\MongoDB Test\Cogs\music.py", line 540, in buttontest
await ctx.send(
TypeError: send() got an unexpected keyword argument 'components'
My current code within the cog:
@cog_ext.cog_slash(name="button", guild_ids=slash_ids)
async def buttontest(self, ctx):
await ctx.send(
"Here is an example of a button",
components=[
[
Button(style=ButtonStyle.green, label="GREEN"),
Button(style=ButtonStyle.red, label="RED"),
Button(style=ButtonStyle.grey, label="GREY", disabled=True),
],
Button(style=ButtonStyle.blue, label="BLUE"),
Button(style=ButtonStyle.URL, label="URL", url="https://www.example.com"),
],
)
I use DiscordComponents(slash) within the Cogs.
Can't use discord-py-slash-commands and this library both
@FeelsBadMan1
How are you catching the interaction?
You would need to do something like this:
res = await client.wait_for("button_click")
#Your user would be
user = res.user #This gives you a Member Object
Or maybe you're catching the wrong type try also using
(ctx.author.id, self.res.user.id)
The error is not from the slash or components library, it's a python error in your skip_check function. It means it's on your end. Try what I sent you and tell me if it works
@kiki7000 Yes there is a way if you want to know what I did add me on discord Shaqalito#2110 also I'm on the server
Can't use discord-py-slash-commands and this library both
I also tried it with discord.py but then the bot is not responsing and i not get any error.
Hello, i got it almost working. I just dont know how i can check using a ifstatement in a command if a button is clicked. There is a examplecode event but this run everytime someone cklicks it with the same answer you definied within the event. but now i want to create different buttons with different responses to each differnt command. i really tried lots of things with ifstatements etc. but none of those helped me with that. it would be great, if someone is so kind and get a solution for me.
Hello, i got it almost working. I just dont know how i can check using a ifstatement in a command if a button is clicked. There is a examplecode event but this run everytime someone cklicks it with the same answer you definied within the event. but now i want to create different buttons with different responses to each differnt command. i really tried lots of things with ifstatements etc. but none of those helped me with that. it would be great, if someone is so kind and get a solution for me.
Dm me on discord
Hello, i now sucessfully made buttons working in the mainfile. now im trying to get it into cogs and used a examplecode in the examplefolder on this githubpage. However i get a dumb issure. I will provide the code im using and the error that appears when running the command below: