NodeJS で «Canvas» ライブラリを使用すると問題が発生します。ターミナルでこのコマンドを起動すると:
node .
端末は私にこれを返信します:
module.js:549
throw err;
^
Error: Cannot find module '../build/Release/canvas.node'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/user/nodejs-canvas/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
そして、私はその理由を理解していません。
index.jsファイルは次のとおりです。
const Discord = require('discord.js');
const Canvas = require('canvas');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('guildMemberAdd', async member => {
const channel = member.guild.channels.find(ch => ch.name === 'member-log');
if (!channel) return;
const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');
const background = await Canvas.loadImage('./wallpaper.jpg');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#74037b';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
ctx.font = '28px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText('Bienvenue,', 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 avatar = await Canvas.loadImage(member.user.displayAvatarURL);
ctx.drawImage(avatar, 25, 25, 200, 200);
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
channel.send(`Bienvenue sur le serveur, ${member}!`, attachment);
});
client.on('message', async message => {
if (message.content === '!join') {
client.emit('guildMemberAdd', message.member || await message.guild.fetchMember(message.author));
}
});
client.login(SECRET TOKEN);
PS : 私はフランス語なので、英語が下手でしたら申し訳ありません。