I want my discord bot to change banner every 20 seconds with current members count, but my method sends static image instead of gif. This is example of code with command setbanner instead of every 20 seconds to change:
@commands.has_role(settings.PROGRAMMER_ROLE_ID)
@client.command(name='setbanner')
async def setbanner(ctx):
banner = Image.open(settings.BANNER_LOCATION)
gif_bytesio = BytesIO()
banner.save(gif_bytesio, format='GIF')
gif_bytesio.seek(0)
await ctx.message.guild.edit(banner=gif_bytesio.read())
I think there is an error in my way to translate GIF image to BytesIO
It isn't working with just GIF image because it doesn't have .read() method, and without read method it says 'File' object has no attribute 'switch'.
Idk why, but the problem is in BytesIO.
I remembered one more way to convert in bytes:
@tasks.loop(seconds=20.0)
async def set_banner():
guild = client.get_guild(settings.GUILD_ID)
helpers.GifEditor(settings.BANNER_LOCATION, settings.EDITED_BANNER_LOCATION, guild)
#creates edited banner
with open(settings.EDITED_BANNER_LOCATION, 'rb') as file:
banner = file.read()
await guild.edit(banner=banner)
Here it is ;)