I have written a code that should get an image from a message in a Discord and save it as an image.
However, when I try to run the program, I get an error.
Error:
Traceback (most recent call last):
File "c:\ExtractImage.py", line 6, in <module>
client = commands.Bot(command_prefix='.')
TypeError: __init__() missing 1 required keyword-only argument: 'intents'
Code:
from discord.ext import commands
import uuid
import requests
import shutil
client = commands.Bot(command_prefix='.')
def send_discord_message():
url = "https://discord.com/api/v9/channels/1095975130758393868/messages"
payload = {
'content': "/generate description:world"
}
header = {
'authorization': 'token'
}
requests.post(url, data=payload, headers=header)
@client.event
async def on_ready():
print("Bot is ready")
@client.command()
async def save(ctx):
try:
url = ctx.message.attachments[0].url
except IndexError:
print("Error: No attachments")
await ctx.send("No attachments detected!")
else:
if url[0:26] == "https://cdn.discordapp.com":
r = requests.get(url, stream=True)
imageName = str(uuid.uuid4()) + '.jpg'
with open(imageName, 'wb') as out_file:
print('Saving image: ' + imageName)
shutil.copyfileobj(r.raw, out_file)
client.run('-')
I would appreciate an answer because I am stuck.