Reputation: 65
I am creating a bot that creates a backup of discord guilds in mysql. (Basically it allows me to make a website that is an extension of the discord channel.) I am going to be downloading and saving attachments in then (guild,channel,user) folder path so I can query them on the website. Also I am going to be purging inactive users by checking to see who is active withing the last 24 hours, last week, etc.
Anyway so I am trying to check to see if a message has an attachment using the following script,
@client.event
def on_message(message):
msg = str(message.content)
channel = str(message.channel)
guild = str(message.guild)
author=str(message.author)
if checkfordb(guild) == 1:
if checkfortable(channel,guild) == 1:
addmsg(channel,guild,msg,author)
else:
createtb(channel,guild)
addmsg(channel,guild,msg,author)
else:
createdb(guild)
createtb(channel,guild)
addmsg(channel,guild,msg,author)
if message.Attachment.size > 0:
print("There is an attachment")
else:
print("There is no attachment")
The problem is that when I run this script I get the following error,
Ignoring exception in on_message
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "bot2.py", line 145, in on_message
if message.Attachment.size > 0:
AttributeError: 'Message' object has no attribute 'Attachment'
So I checked the documentation and sure enough despite tons of other people saying they are using it there is no attachment attribute for message. The documentation under attachment says you can use class discord.attachment. So I looked at the classes and I see no way to pull an attachment when it is posted. Does anyone have any ideas on how to do this?
Any and all help is appreciated.
Upvotes: 2
Views: 18411
Reputation: 345
The correct attribute name is Message.attachments
as Patrick Haugh suggested. You could use the len()
function on that to get the "size" of it since it's just a normal python list
of discord.Attachment
objects.
Upvotes: 2