How can I get the guild icon in ejs?

Im making an ejs dashboard and I’m wondering how I can get the guild icon in an image.

Please help.

What’s a guild icon?

image

something like that

Here: https://stackoverflow.com/questions/61479351/guild-icon-guild-iconurl-not-working-in-embed-thumbnail

Pass the icon url into your EJS body, and then write something like
<img src=<%- data.imgurl -%></img>
Hope this works!

I’ll try it right now, Thanks!!

guild.iconURL();

returns a URL. Pass that through in the ejs render

1 Like

It still has to be served from an EJS object though. Make sure to console.log it before writing - I wrote 50 lines without testing yesterday and had hell to pay.

1 Like

Yes like this ^^^
Define the URL as a variable, pass variable through at ejs render, use variable in img tag with ejs code :slight_smile:

1 Like
var iconurl = client.guilds.get("the guild id").iconURL();

@HK420 Use this ^^^
I checked and I am pretty sure it works with v12

1 Like

Ah, I forgot about breaking changes in v12

1 Like

I know, it’s a pain. Not only do you have to help people, but also check it’s right for v12
This helps a lot:
https://discordjs.guide/additional-info/changes-in-v12.html

1 Like

wasn’t it client.guilds.cache.get?

You can use either I believe. One uses cache and therefore you may not have it in cache and get errors. The other doesn’t so you won’t get errors, but it just takes a tad bit longer to load

https://discordjs.guide/popular-topics/common-questions.html

  • <guild> is a placeholder for the Guild object, such as <message>.guild or <client>.guilds.cache.get('<id>') .

or
https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/frequently-asked-questions.md

// Get a Guild by ID
client.guilds.get("the guild id");
// Returns <Guild>

@HK420 Let me know if it works :slight_smile:
I would use the non-cache version, but you can choose. Note: the use of one over the other comes at the cost of either errors or time
Edit: did a bit of research and maybe you have to add cache now in v12. Try both and use the one that works

Any way I can put it in a url tag in css?
image

anyone???

<script> tags will work just fine, as they can be in an ejs file. Or use Javascript to change the CSS with the ejs variables. <script> tags will be the easiest way

Will the script tag actually work? :0

Can you give me an example?

Assuming the element “elem”, you could do something like

elem.style.backgroundImage = "url(.....)"

docs: https://www.w3schools.com/cssref/pr_background-image.asp