discord.py - Is there a way to change a server's logo?

Viewed 140

I am creating a discord bot for someone that is advanced and required to have some good features, so I want to know if you could change a logo of a server simply with a command in discord.py

So basically, if It has a feature. Would it look like this? is it Correct?

ctx.guild.change_logo("URL")
2 Answers

Guild.edit method allows for changing of the icon. Keep in mind that you need MANAGE_GUILD permissions to do that.

# Open file in binary mode, because icon needs to be a byte-like object
with open(path_to_image, "b") as file:
    icon: bytes = file.read()
    await ctx.guild.edit(icon=icon)

You can assign the image to a variable:

icon = "image.jpg"

If the image is not in the same folder as your script try to called the variable with the full direction to the image.

icon = "C:\User\Name\Desktop\image.jpg"

Then use the function guild.change_logo with the variable icon.

Related