Good afternoon everyone,
I’m developing discord bots on glitch, I already made some progress,
But I made the code that if someone joins a guild that my bot sends in a channel a picture with a welcome and edited with canvas (a package) that it gives the username in the picture, also his profile picture. But when it sends the message it returns an error that he can’t send an empty message, I know where the error comes from. I uploaded the pictures that i want to use in the assets folder but i can’t get the right path to it. Can someone please give me the path to the assets folder so i can continue with my project? Thanks.
Good afternoon everyone,
The assets folder in the editor is a virtual folder and doesn’t exist locally in the project, so there’s no path that canvas can use. I suggest creating a folder locally and uploading the images to that. You can use ‘wget url’ from the command line, where url is the asset url for each image you uploaded to the assets folder.
i would like to go for your first idea, could you tell me how i can create a folder with pictures?
and just a question could you be more specific about wget url?
like how could i use it here?
const w = [’./assets/w6.jpg’];
const w = [‘https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521’,‘https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw3.jpg?1531238961647’,’.https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw2.jpg?1531238963111’,'https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw1.jpg?1531238964243’];
thanks for fast reply!
@Laceh wget is a console command, so you use like Gareth said
wget image_url in your project console.
Just take all those urls and use like I and Gareth said
I did that and I tried it again but still doesn’t work what path do I need to use? the link? the png name? ./assets/idk.png? Could you be a little more specific to help also other people on this forum
Go to the assets folder in your project and select the image you want to upload locally to your Glitch project. Click on the ‘copy url’ button. This will copy an image url like
https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521to your clipboard.
Go to the console in Glitch, and if you don’t already have an assets folder, type
mkdir assetsand hit enter.
cd assetsand hit enter to move into the assets folder
wgetand then paste the image url you copied previously into the console, so you see something like
wget https://cdn.glitch.com/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521and hit enter. That’ll import that image to your assets folder. Note that it’ll be imported with the name
f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521. To make it easier to deal with you’ll want to rename it. To do so, type
mv /app/assets/f6254aa9-8051-48db-bbc1-5e7766f748c5%2Fw6.jpg?1531238960521 /app/assets/w6.jpgand hit enter. You can confirm the asset renamed correctly by typing
ls -aland you’ll see a list of files, one of which should be called
Repeat steps 1 and 4 for each image you want to upload. Be sure to change the name of the file to the relevant one in step 4.
The path you’ll then use is:
__dirname + '/assets/w6.jpg'
Asset help for Discord Canvas
Discord.js | Node-Canvas
I’ll try it out thank you very much but a question: what is __dirname?
It’s a node.js variable that outputs the directory name of the current module. It’s a reliable way of constructing a direct path to an asset as relative paths can be confusing.
so this folder is right? ./assets/w6.jpg?
__dirname + '/assets/w6.jpg'
Um, I have received errors…?
When I tried to move it and rename
app@src-serifix-2006:~/assets 13:09 $ mv /app/assets/25c586c2-b21d-4b30-9ce4-f194469005a4%2FSX%20-%20Welcome%20Banner.png?1531160208914 /app/assets/welcome.png mv: cannot stat '/app/assets/25c586c2-b21d-4b30-9ce4-f194469005a4%2FSX%20-%20Welcome%20Banner.png?1531160208914': No such file or directory
Yes, I have ran
mdkir assets, then
cd assets and the other commands
ls -al and copy the file name that’s listed so you know you’re specifying it correctly.
When I run that, I get
app@src-serifix-2006:~/assets 13:11 $ ls -al total 228 drwxr-xr-x 1 app app 152 Jul 11 13:09 . drwxr-xr-x 1 app app 696 Jul 11 13:04 .. -rw-r--r-- 1 app app 213922 Jul 9 18:16 25c586c2-b21d-4b30-9ce4-f194469005a4%2FSX - Welcome Banner.png?1531160208914
I got it working with wget and the url but i still don’t get it with the __dirname + /assets/imgname
can you give me an expample? like how should u use it here?
const pictures = [’./assets/w1.jpg’];
is this right? and is it possible to change the assets name to /img?
const pictures = [__dirname + './assets/imgname']
Hey Gareth, for
app do we replace that with our project name?
No, app is the folder where all your project files are. It doesn’t change between projects. The issue moving the file is because you have spaces in the file name. Try wrapping it in quotes e.g.
mv "/app/assets/25c586c2-b21d-4b30-9ce4-f194469005a4%2FSX - Welcome Banner.png?1531160208914" /app/assets/welcome.png
Are you able to get on my project and for it for me? Honestly, I think I did something wrong, but I do know I followed each step and tried to call it by
__dirname + './assets/Welcome.png' + I also tried it with the same thing, except I did the CDN code instead.
It should just be
__dirname + '/assets/Welcome.png' not
__dirname + './assets/Welcome.png'