pycord icon indicating copy to clipboard operation
pycord copied to clipboard

AttributeError: 'Interaction' object has no attribute 'edit_message'

Open pratheek78 opened this issue 5 years ago • 3 comments

Summary

Error when editing the message using a dropdown

Reproduction Steps

make a dropdown by subclassing discord.ui.View, then make if statements and in those add await interaction.edit_message()

Minimal Reproducible Code

import discord
from discord import message
from discord.ext import commands
from discord.ui.select import select

class HelpView(discord.ui.View):
    @discord.ui.select(placeholder = 'Select A Command Category Here', min_values = 1, max_values = 1, options = [
     discord.SelectOption(label = 'Moderation', description = "Shows Info About All the moderation commands.", emoji = '🔨', value= 'moderation'),
     discord.SelectOption(label = 'Administration', description = "Shows all the admin commands. Not A Lot of stuff here.", emoji = '⚙️', value = 'admin'),
     discord.SelectOption(label = 'Information', description = "Shows All the Info Commands", emoji = '❓' , value = 'info'),
     discord.SelectOption(label = 'Fun', description = "Shows All the Fun Commands", emoji = '🎠', value= 'fun'),
     discord.SelectOption(label = "Misc", description = "Shows the Misc Commands", emoji = '🎭', value='misc')
    ])
    async def select_callback(self, select: discord.ui.Select, interaction: discord.Interaction):
        if select.values[0] == 'moderation':
            await interaction.edit_message(content = 'opt1')
        
        elif select.values[0] == 'admin':
            await interaction.edit_message(content ='opt2')
        
        


class HelpCommand(commands.Cog):
    def __init__(self, client):
        self.client = client


    @commands.command()
    async def help(self, ctx, cmd = None):
        await ctx.send('test test test', view = HelpView(timeout=10))

Expected Results

Expected result is that it edits the message with the given string, in this case "opt1" or "opt2"

Actual Results

Ignoring exception in view for item <Select placeholder='Select A Command Category Here' min_values=1 max_values=1 options=[<SelectOption label='Moderation' value='moderation' description='Shows Info About All the moderation commands.' emoji= default=False>, <SelectOption label='Administration' value='admin' description='Shows all the admin commands. Not A Lot of stuff here.' emoji= default=False>, <SelectOption label='Information' value='info' description='Shows All the Info Commands' emoji= default=False>, <SelectOption label='Fun' value='fun' description='Shows All the Fun Commands' emoji= default=False>, <SelectOption label='Misc' value='misc' description='Shows the Misc Commands' emoji= default=False>] disabled=False>: Traceback (most recent call last): File "C:\Python Installation\Python39\lib\site-packages\discord\ui\view.py", line 365, in _scheduled_task await item.callback(interaction) File "c:\Users\prath\Desktop\Python\Projects\discord bot\cogs\help.py", line 19, in select_callback await interaction.edit_message(content ='opt2') AttributeError: 'Interaction' object has no attribute 'edit_message'

Intents

intents = discord.Intents.all()

System Information

  • Python v3.9.6-final
  • py-cord v2.0.0-alpha
    • py-cord pkg_resources: v2.0.0a4433+gf51a1ae6
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.22499

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

No response

pratheek78 avatar Nov 22 '21 07:11 pratheek78

an interaction cannot edit the message, you need to call edit on the message itself

Lulalaby avatar Nov 22 '21 07:11 Lulalaby

Duplicate of #444

Lulalaby avatar Nov 22 '21 07:11 Lulalaby

You might be looking for InteractionResponse.edit_message or interaction.response.edit_message instead (just because these methods are similar)...

esmaycat avatar Nov 22 '21 18:11 esmaycat