Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.93k stars 3.77k forks source link

I need help with an AttributeError #732

Closed calebcmn closed 7 years ago

calebcmn commented 7 years ago

I am making a discord bot in python. Today, I was coding a 'say' command, where the goal is:

User: [p]say Hello!

 

Bot: Hello!

 

User's message deleted

 

The code I have so far is this:

 

@commands.command(pass_context=True, no_pm=True)
async def say(self, ctx, *, text):
    """Tell RudeBot to say something."""
    channel = ctx.message.channel
    await self.bot.send_message(channel, text)
    await self.bot.delete_message(channel)

 

When I attempt to run the command, the bot returns the message but does not delete the user's message. The output in the console is this:

 

[24/08/2017 22:04] ERROR red on_command_error 369: Exception in command 'say'
Traceback (most recent call last):
  File "lib/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/cmncaleb/RudeBot/cogs/general.py", line 78, in say
    await self.bot.delete_message(channel)
  File "lib/discord/client.py", line 1261, in delete_message
    channel = message.channel
AttributeError: 'Channel' object has no attribute 'channel'

 

I would really like some help fixing this, and if you need any more info just let me know!

slice commented 7 years ago

await self.bot.delete_message(channel)

http://discordpy.readthedocs.io/en/latest/api.html#discord.Client.delete_message

tylergibbs2 commented 7 years ago

The code that you sent does not correlate at all with the traceback that you included.

calebcmn commented 7 years ago

@TheTrain2000 sorry about that, slight typo. I edited the message.

calebcmn commented 7 years ago

@slice I meant to have that included, I just copied too little of my code.

tylergibbs2 commented 7 years ago

slice is pointing out the fact that you should read the documentation for delete_message, rather than saying that you didn't include it in your code snippet. On the last line of your code you have await self.bot.delete_message(channel), when you should in fact be doing await self.bot.delete_message(ctx.message) because according to the docs, delete_message() takes a Message object.

calebcmn commented 7 years ago

@TheTrain2000 sorry, I'm quite new to python, and I did indeed head over to read the docs before reporting the issue here but I couldn't understand it.