Panda
Panda
DIAdiscord.js - Imagine an app
Created by Panda on 6/21/2023 in #djs-questions
SequelizeDatabaseError because of array?
Hello 👋 So I am trying to make a database This code works just fine
const Sequelize = require("sequelize");
const sequelize = require("../utils/database");

const Guild = sequelize.define("guild", {
id: {
type: Sequelize.STRING,
primaryKey: true,
},
applicantChannelId: {
type: Sequelize.STRING,
allowNull: true,
},
});

module.exports = Guild;
const Sequelize = require("sequelize");
const sequelize = require("../utils/database");

const Guild = sequelize.define("guild", {
id: {
type: Sequelize.STRING,
primaryKey: true,
},
applicantChannelId: {
type: Sequelize.STRING,
allowNull: true,
},
});

module.exports = Guild;
But once I try to do this but with an array I get an arror
const Sequelize = require("sequelize");
const sequelize = require("../utils/database");

const Guild = sequelize.define("guild", {
id: {
type: Sequelize.STRING,
primaryKey: true,
},
applicantChannelId: {
type: Sequelize.STRING,
allowNull: true,
},
applicationQuestions: {
type: Sequelize.ARRAY(Sequelize.STRING),
allowNull: true,
},
});

module.exports = Guild;
const Sequelize = require("sequelize");
const sequelize = require("../utils/database");

const Guild = sequelize.define("guild", {
id: {
type: Sequelize.STRING,
primaryKey: true,
},
applicantChannelId: {
type: Sequelize.STRING,
allowNull: true,
},
applicationQuestions: {
type: Sequelize.ARRAY(Sequelize.STRING),
allowNull: true,
},
});

module.exports = Guild;
ERROR:
name: 'SequelizeDatabaseError',
parent: [Error: SQLITE_ERROR: near "[]": syntax error] {
errno: 1,
code: 'SQLITE_ERROR',
sql: 'ALTER TABLE `guilds` ADD `applicationQuestions` VARCHAR(255)[];'
},
original: [Error: SQLITE_ERROR: near "[]": syntax error] {
errno: 1,
code: 'SQLITE_ERROR',
sql: 'ALTER TABLE `guilds` ADD `applicationQuestions` VARCHAR(255)[];'
},
sql: 'ALTER TABLE `guilds` ADD `applicationQuestions` VARCHAR(255)[];',
parameters: {}
}
name: 'SequelizeDatabaseError',
parent: [Error: SQLITE_ERROR: near "[]": syntax error] {
errno: 1,
code: 'SQLITE_ERROR',
sql: 'ALTER TABLE `guilds` ADD `applicationQuestions` VARCHAR(255)[];'
},
original: [Error: SQLITE_ERROR: near "[]": syntax error] {
errno: 1,
code: 'SQLITE_ERROR',
sql: 'ALTER TABLE `guilds` ADD `applicationQuestions` VARCHAR(255)[];'
},
sql: 'ALTER TABLE `guilds` ADD `applicationQuestions` VARCHAR(255)[];',
parameters: {}
}
I'd appreciate some help ;D
6 replies
DIAdiscord.js - Imagine an app
Created by Panda on 6/20/2023 in #djs-questions
Using Buttons Properly
6 replies
DIAdiscord.js - Imagine an app
Created by Panda on 6/20/2023 in #djs-questions
Getting a Type Error on getApplicationCommand function
Hello 👋 I have been learning how to make a discord bot and wanted to make an advanced command + event handler. One of the things that I have found that I have to do is the getApplicationCommand.js function Here is the code for said file
module.exports = async (client, guildId) => {
let applicationCommands;

if (guildId) {
const guild = await client.guilds.fetch(guildId);
applicationCommands = guild.commands;
} else {
applicationCommands = await client.application.commands;
}

await applicationCommands.fetch();
return applicationCommands;
};
module.exports = async (client, guildId) => {
let applicationCommands;

if (guildId) {
const guild = await client.guilds.fetch(guildId);
applicationCommands = guild.commands;
} else {
applicationCommands = await client.application.commands;
}

await applicationCommands.fetch();
return applicationCommands;
};
For some reason, I get this error: TypeError: Cannot read properties of undefined (reading 'fetch') Any ideas?
17 replies
DIAdiscord.js - Imagine an app
Created by Panda on 2/26/2023 in #djs-questions
Bot treating register-commands.js file like its not there.
This is my index.js
require("dotenv").config();
const { Client, IntentsBitField } = require("discord.js");

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on("ready", (c) => {
console.log(`${c.user.username} is online.`);
});

client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName == "ping") {
interaction.reply("Pong!");
}
});

client.login(process.env.TOKEN);
require("dotenv").config();
const { Client, IntentsBitField } = require("discord.js");

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on("ready", (c) => {
console.log(`${c.user.username} is online.`);
});

client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName == "ping") {
interaction.reply("Pong!");
}
});

client.login(process.env.TOKEN);
And this is my register-commands.js
require("dotenv").config();
const { REST, Routes } = require("discord.js");

const commands = [
{
name: "ping",
description: "Replies with Pong!",
},
];

const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);

(async () => {
try {
console.log("Started refreshing application (/) commands.");

await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), {
body: commands,
});

console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();
require("dotenv").config();
const { REST, Routes } = require("discord.js");

const commands = [
{
name: "ping",
description: "Replies with Pong!",
},
];

const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);

(async () => {
try {
console.log("Started refreshing application (/) commands.");

await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), {
body: commands,
});

console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();
It doesn't recognise that the file exists, and im not getting my /ping command in discord
24 replies