Answer the question
In order to leave comments, you need to log in
Command raised an exception: AttributeError: 'File' object has no attribute 'startswith' what to do?
The code:
@bot.command() #22
async def change_banner(ctx):
file = discord.File('my_image.png')
await ctx.send(file = file)
await ctx.guild.edit(banner = file) # При помощи метода read() читаем изображение, и ставим его как баннер на сервере
os.remove(file) # Удаляем скачанное изображение
Ignoring exception in command change_banner:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/container/bot.py", line 1923, in change_banner
await ctx.guild.edit(banner = file) # При помощи метода read() читаем изображение, и ставим его как баннер на сервере
File "/home/container/.local/lib/python3.9/site-packages/discord/guild.py", line 1186, in edit
banner = utils._bytes_to_base64_data(banner_bytes)
File "/home/container/.local/lib/python3.9/site-packages/discord/utils.py", line 323, in _bytes_to_base64_data
mime = _get_mime_type_for_image(data)
File "/home/container/.local/lib/python3.9/site-packages/discord/utils.py", line 310, in _get_mime_type_for_image
if data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'):
AttributeError: 'File' object has no attribute 'startswith'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'File' object has no attribute 'startswith'
await ctx.guild.edit(banner = file)
Answer the question
In order to leave comments, you need to log in
@client.command(aliases=['banner'])
async def __avasstar(ctx):
with open('image.jpg', 'rb') as f: #с пк берёт картинку
icon = f.read() #читаем её
await ctx.guild.edit(banner = icon) #устанавливаем
The docs say :
banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question