0
votes

Hi I'm having an issue with auto deleting a message with is an embed here is what I'm working with

@commands.command(name='hug', pass_context=True, aliases=['hugs'])
    @commands.cooldown(5, 60, commands.BucketType.user)
    async def hug(self, context, member: discord.Member):
        """Hug your friend"""
        author = context.message.author.mention
        mention = member.mention

        hug = "{0} hugs {1}"

        choices = ['example.gif']

        image = random.choice(choices)

        embed = discord.Embed(description=hug.format(author, mention), colour=discord.Color(random.randint(0x000000, 0xFFFFFF)))
        embed.set_image(url=image)

        await self.bot.say(embed=embed)
        await asyncio.sleep(3) 
        await self.bot.delete_message(embed)

Seems like I'm doing something wrong here as it will throw back an error

File "C:\Users\Tom\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 1261, in delete_message
    channel = message.channel
AttributeError: 'Embed' object has no attribute 'channel'
2

2 Answers

0
votes

You delete the message the Embed is in, not the Embed itself.

sent = await self.bot.say(embed=embed)
await asyncio.sleep(3) 
await self.bot.delete_message(sent)
0
votes

For rewrite it is now

# For on_message
await message.delete()

# For commands
await ctx.message.delete()

and for removing embeds when editting

# msg would be when you send the message Ex. msg = await ctx.send(embed=embed)
# Make sure to specify what you want to edit with 'content' and 'embed'
await msg.edit(content='Content Here', embed=None)