#How to add buttons in nextcord?

8 messages · Page 1 of 1 (latest)

surreal forge
#

I am not that experienced so I am using chatgpt to help me with buttons and stuff.

  ...
  # Define button callbacks
        async def left_callback(interaction: nextcord.Interaction):
            nonlocal current_video_index, current_video_path
            ...

        async def right_callback(interaction: nextcord.Interaction):
            nonlocal current_video_index, current_video_path
            ...

        async def cross_callback(interaction: nextcord.Interaction):
            nonlocal current_video_path
            os.remove(current_video_path)
            await interaction.message.delete()

        # Add buttons to the embed
        left_button = nextcord.ui.Button(label="<", custom_id="left_button")
        right_button = nextcord.ui.Button(label=">", custom_id="right_button")
        cross_button = nextcord.ui.Button(label="X", custom_id="cross_button", style=nextcord.ButtonStyle.red)
        left_button.callback = left_callback
        right_button.callback = right_callback
        cross_button.callback = cross_callback

        buttons_row = nextcord.components.ActionRow(left_button, right_button, cross_button)
        await message.edit(components=[buttons_row])
        await message.edit(components=message_component)

This is the code that chatgpt come up with but I cant find a way to make it work. Any help would be appreciated

#

Also using this type to code discord bot

class BotEngine(nextcord.Client):
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
#

The code fails at nextcord.components.ActionRow

#

I am trying some combos on how to make it wor

#

but nothing is working

surreal forge
#

Ok

#

I figured it out