Home > Software design >  I can't interact with button on discord.py
I can't interact with button on discord.py

Time:08-24

I have a problem with my Discord bot. I made an embed and a button. They work properely but I can't interact with button I made. I imported all 3rd party addons for this. When I try to interact, I got this error AttributeError: 'Button' object has no attribute 'response'

Here is my codes;

class Menu(discord.ui.View):
    def __init__(self):
        super().__init__()
        self.value = None

    @discord.ui.button(label="Send Message", style=discord.ButtonStyle.grey)
    async def menu1(self, button: discord.ui.Button, interaction: discord.Interaction):
        await interaction.response.send_message("Hello you clicked me")


@Bot.command()
async def embed_with_buttons(ctx):
    view = Menu()
    embed = discord.Embed(colour=0xFF5733, title="Title", type="rich", url=None, description="description", timestamp=None)
    await ctx.send(embed=embed, view=view)

And my Imports;

import discord
from discord.ext import commands
from utils import *
from functions import *
import time
import interactions
from discord.ui import Button
from interactions import Button, ButtonStyle, SelectMenu, SelectOption
import random

My code looks like this in pycharm IDE;

codes imports

CodePudding user response:

You have the order of the parameters swapped. It should be:

async def menu1(self, interaction: discord.Interaction, button: discord.ui.Button):

This was changed before the stable release of discord.py 2.0

  • Related