Node JS Error canvas.node is not a valid Win32 application - javascript

im trying to make a plugin discord in js and add the package: discord-image-generation but i need to have canvas installed on my PC, when i try to run it it's give me the error:
C:\Users\USER\node_modules\canvas\build\Release\canvas.node is not a valid Win32 application.
Here is my code:
const Discord = require("discordjs")
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
const DIG = require("discord-image-generation");
client.on("ready", () =>
{
});
client.on("message", message =>
{
let cmd = message.content.split(" ")[0]
cmd = cmd.slice(PREFIX.length)
let args = message.content.split(" ").slice(1)
if (cmd === "deletetrash")
{
message.delete()
const user = message.mentions.users.first()
if (!user) return window.BdApi.alert("🔪 Eroge Notification 🔪",`You need mention someone. ❌`);
Delete();
async function Delete()
{
let image = await new DIG.Delete().getImage(user.avatarURL).then(image =>
{
message.channel.send({
files: [{
attachment: image,
name: "Delete.png"
}]
})
})
}
}
});
client.login(get_token.authToken).catch(() =>
{
return window.BdApi.alert("🔪 Eroge Notification 🔪",`Oops, look like your token not working...`);
})
i have tried every solutions nothing work, thanks in advance for your help!

It means, that canvas build version and nodejs version are not the same. i.e. x32 canvas build and x64 nodejs build. Just build canvas for your node version

Related

How to store the ID of the user who sent a slash command and compare with user who interacted with a button in Discord.js

I'm using the following code to create a quick database to store the ID of the user who called a bot via a slash command. I then want to compare this ID with the ID of the person interacting with the bot. My aim is to prevent anyone but the user that called the bot being able to interact with it.
The following code works but it's temperamental in that it fails without a clear reason on occasion (i.e. it returns the error which states that the person interacting isn't the person who sent the slash command even if they are).
I'm new to discord.js and quick.db tables so I'm hoping someone more competent than me has a better way of achieving this.
const { Client, Intents, MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'),
client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES ] });
client.db = require("quick.db");
var quiz = require("./quiz.json");
client.login(config.token);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
if ([null, undefined].includes(client.db.get(`quiz`))) client.db.set(`quiz`, {});
if ([null, undefined].includes(client.db.get(`quiz.spawns`))) client.db.set(`quiz.spawns`, {});
});
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "unlock") {
message.delete();
const m = await message.channel.send(getMMenuPage());
client.db.set(`quiz.spawns.m${m.id}`, message.author.id);
}
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isButton()) {
if (client.db.get(`quiz.spawns.m${interaction.message.id}`) != interaction.user.id) return interaction.reply(getMessagePermissionError(client.db.get(`quiz.spawns.m${interaction.message.id}`)));
const q = quiz;
Please let me know if you need more information.
Thanks.
Instead of using:
const db = require("quick.db");
You should be using:
const { QuickDB } = require("quick.db");
const db = new QuickDB();
Other than that I haven't see any problems.

DiscordJs registered command dont show up

I want to build a discord bot with slash commands. I use the following script to register the commands:
index.js
require("dotenv").config();
const fs = require("node:fs");
const { REST } = require("#discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const { Client, Intents, Collection, Interaction, ClientUser } = require('discord.js');
// Create a new client instance
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGES
]
});
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
const commands = [];
const GUILDID = process.env.GUILDID;
client.commands = new Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
};
const rest = new REST ({version: "9"}).setToken(process.env.TOKEN);
client.once("ready", () => {
console.log("Ready");
console.log(commands);
const CLIENT_ID = client.user.id;
(async () => {
try {
if(process.env.ENV === "production"){
await rest.put(Routes.applicationCommands(CLIENT_ID),{
body: commands
});
console.log("Successfully registered commands globally");
} else {
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILDID), {
body: commands
});
console.log("Successfully registered commands locally");
}
} catch (err) {
if (err) console.error(err);
}
})();
});
client.login(process.env.TOKEN);
I have one command so far called "ping.js" which is in the commands folder, which is in my project folder.
ping.js
const { SlashCommandBuilder } = require("#discordjs/builders");
module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("pong"),
async execute(interaction) {
interaction.reply({
content: "Pong",
ephemeral: true
})
}
}
I also have an .env file in the project folder.
ENV=test
TOKEN=****
GUILDID=****
The script runs without errors and I get "Successfully registered commands locally" as a feedback, but the command dont show up in Discord. I have tried to register the bot again, restart my PC and the terminal and I have checked the code multiple times.
Whats make this a bit frustrating is that it first works and let me run the ping command, but after adding another command, the new one dont showed up. And now I have deleted the secound command again but cant get back.
Thank you all very much for you help in advance
Update:
Following the advise from Gh0st I have added the line console.log(commands) which gives me the following response:
Ready
[
{
name: 'ping',
name_localizations: undefined,
description: 'pong',
description_localizations: undefined,
options: [],
default_permission: undefined
}
]
Successfully registered commands locally
To me it seems that the for loop works since they are in the array, but they commands still dont show up in Discord.

send an image using discord.js

I have been following a few different guides to program a simple discord bot. Everything works except I cannot get it to send an image. I have looked at these previous questions 1 2, but their solutions are not working for me. This is my code:
const {Client, Intents} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '?';
client.once('ready', () => {
console.log("Dog is online!");
});
client.on('messageCreate', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping') {
message.channel.send('pong!');
}
else if (command === 'bark') {
message.channel.send('bark bark bark grrrr...')
}
else if(command === 'nick') {
message.channel.send('grrr...');
}
else if (command === 'pic') {
message.channel.send("little dog", {files: ["https://i.imgur.com/xxXXXxx.jpeg"] });
}
});
//must be last line
client.login('');
my client login is there in my editor, just not sharing it here. the "pic" command is what is not working. It displays the "little dog" text, but does not send the image. The only reason I'm using imgur is because I'm not sure if you can send local images; if someone knows a solution using local files I'll take it.
You can use
files: [{ attachment: "YourImage.jpg" }] });
You can also rename the image with
files: [{ attachment: <images>.toBuffer(), name: 'newName.png' }] });
Example:
message.channel.send({ files: [{ attachment: 'YourImage.png' }] });
the <images> is your image variable
const images = blablabla
According to the V13 discord.js
You can do following, this is also working for me.
const { MessageAttachment } = require('discord.js')
const attachment = new MessageAttachment('URL'); //ex. https://i.imgur.com/random.jpg
message.channel.send({ content: "I sent you a photo!", files: [attachment] })
This example will send a photo with the text I sent you a photo!

Is there a way to get user from mention discordjs v12?

Sorry if there are any typos, but english is not my first language.
Hi, I have a problem when I am trying to get userinfo from a mention. It works perfectly fine when I am doing the command on a non nicknamed user, but when I try on a nicknamed user, it only returns undefined.
Keep in mind that I am using WOKCommands to handle my slash commands, and the error is happening on a slash command.
Here is the code for the command:
const { MessageEmbed } = require('discord.js');
const moment = require('moment');
module.exports = {
slash: true,
testOnly: true,
description: 'En spioneringskommando.',
minArgs: 1,
expectedArgs: '<Mention>',
callback: ({ args, client, interaction }) => {
const userId = args[0].toString().replace(/[\\<>##&!]/g, "");
const guild = client.guilds.cache.get(interaction.guild_id);
const member = guild.members.cache.get(userId);
const embed = new MessageEmbed()
.setTitle("Spioneringsprogram v1.0")
.setDescription(`Bruker: ${member.user.username}`)
.setColor("RANDOM")
.addField("Kallenavn:", `${member.nickname ? `${member.nickname}` : 'Ingen'}`, false)
.addField("Ble medlem av discord:", `${moment.utc(member.user.createdAt).format('DD/MM/YY')}`, false)
.addField("Ble medlem av discord serveren:", `${moment.utc(member.joinedAt).format('DD/MM/YY')}`, false)
.setFooter(`ID: ${member.user.id}`)
.setTimestamp();
return embed;
}
}
And here is my index.js file:
require('dotenv').config();
const Discord = require("discord.js");
const WOKCommands = require('wokcommands');
const client = new Discord.Client();
const guildId = 'censored'
client.on('ready', () => {
console.log("Bot is ready!");
new WOKCommands(client, {
commandsDir: 'commands',
testServers: [guildId],
showWarns: false
});
});
Thanks for any help I can get.
since you got the command as a slash command ("slashCommand:true")
You should be using "interaction."
examples:
(interaction.user.username) // The username of the interaction's user
(interaction.user.id) // The id of the interaction's user
(interaction.user.avatarURL)// The avatar's url of the interaction's user
But you seem to be new to wokcommands, and slash commands at general, so contact me at: Glowy#8213
And i'll help you out

Why does it say error finding module when I already installed it

I am trying to code a discord music bot and this is my code:
const config = require('config.json')
const Discord = require('discord.js');
const ffmpeg = require('ffmpeg-extra')
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if(message.content.toLocaleLowerCase() === "elevator"){
if(message.member.voice.channel){
message.channel.send("Thanks to https://www.bensound.com for supplying us with this music.")
play(message.member.voice.channel)
}
else {
message.channel.send("Yo, please join a VC first.")
}
}
});
async function play(voiceChannel) {
const connection = await voiceChannel.join();
connection.play('elevator.mp3');
}
client.login(config.token);
For some reason even though I installed ffmpeg via npm install ffmpeg it says:
Error: Cannot find module 'ffmpeg-extra'
EDIT: When I use const ffmpeg = require("ffmpeg") I get this error:
UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv not found!
I think you require the wrong package.
ffmpeg-extra is not a public package.
ffmpeg exists here.
extra-ffmpeg exists here.
Maybe you have to require one of those two package.

Categories