Reputation: 99
Above is my code, However, I am getting an Error:-
‘Parsing Error: The keyword ‘await’ is reserved’
The line where my Error is occurring is below. Help me if you can please.
I get the error of the first line of this bit of code
if you can help, it'd be greatly appreciated as I am struggling a lot with this issue. Thank you again!
const { body: buffer } = await snekfetch.get(member.user.displayAvatarURL);
const avatar = await Canvas.loadImage(buffer);
ctx.drawImage(avatar, 25, 25, 200, 200);
if (!channel) return;
const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');
const { body:buf } = await snekfetch.get('https://cdn.glitch.com/6ec6dccb-f1a9-4c03-b4f1-d6c639e188c9%2Fwallpaper.jpg?1532779841254');
const background = await Canvas.loadImage(buffer);
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#74037b';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
// Slightly smaller text placed above the member's display name
ctx.font = '28px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText('Welcome to the server,', canvas.width / 2.5, canvas.height / 3.5);
// Add an exclamation point here and below
ctx.font = applyText(canvas, `${member.displayName}!`);
ctx.fillStyle = '#ffffff';
ctx.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);
ctx.beginPath();
ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();
const { body: buffer } = await snekfetch.get(member.user.displayAvatarURL);
const avatar = await Canvas.loadImage(buffer);
ctx.drawImage(avatar, 25, 25, 200, 200);
const attachment = new Discord.Attachment(canvas.toBuffer(), 'welcome-image.png');
channel.send(`Welcome to the server, ${member}!`, attachment);
});
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#74037b';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
// Slightly smaller text placed above the member's display name
ctx.font = '28px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText('Welcome to the server,', canvas.width / 2.5, canvas.height / 3.5);
// Add an exclamation point here and below
ctx.font = applyText(canvas, `${member.displayName}!`);
ctx.fillStyle = '#ffffff';
ctx.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);
ctx.beginPath();
ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();
const { body: buffer } = await snekfetch.get(member.user.displayAvatarURL);
const avatar = await Canvas.loadImage(buffer);
ctx.drawImage(avatar, 25, 25, 200, 200);
const attachment = new Discord.Attachment(canvas.toBuffer(), 'welcome-image.png');
channel.send(`Welcome to the server, ${member}!`, attachment);
});
Upvotes: 0
Views: 1089
Reputation: 1893
await
is only valid inside an async function. I can't see the function definition from the code you have posted but my first guess would be that it is a plain old function.
eg. if your code looks like:
function main() {
// ...code
const { body: buffer } = await snekfetch.get(member.user.displayAvatarURL);
// ...code
}
then you'll have problems, you need the async
keyword before the function
keyword
If you were to be trying to use arrow functions, a similar requirement would be in place:
const main = async () => {
// code...
const {body: buffer} = await snekfetch.get(member.user.displayAvatarURL);
// more code...
}
Also a note that the async keyword applies only to the function it is immediately attached to, not recursively down to every function that you define inside that function. So for instance, you could NOT do:
const main = async () => {
// code...
const getAvatar = () => {
const {body: buffer} = await snekfetch.get(member.user.displayAvatarURL);
};
// more code...
}
That would be a syntax error because await is used inside a function which was not declared as async, instead you would need to do:
const main = () => {
// code...
const getAvatar = async () => {
const {body: buffer} = await snekfetch.get(member.user.displayAvatarURL);
};
// more code...
}
Upvotes: 4