channels.create().then() runs before the result is acquired

Trying to figure out why my query is getting ran before the result is acquired here:
const guildCategory = interaction.guild.channels.create({name: "Guilds", type: ChannelType.GuildCategory}).then((result)=>{
//Runs before it should VVV
connection.query(`INSERT INTO \`ServerSettings\` (\`serverID\`, \`guildsCategory\`) VALUES (${interaction.guild.id},${result.id})`,
function(err,result,fields){
if(err) {
interaction.reply('An Error Occurred: While trying to add the channels to the database.')
console.error(err)
}
else interaction.reply('Setup Completed');
});
});
const guildCategory = interaction.guild.channels.create({name: "Guilds", type: ChannelType.GuildCategory}).then((result)=>{
//Runs before it should VVV
connection.query(`INSERT INTO \`ServerSettings\` (\`serverID\`, \`guildsCategory\`) VALUES (${interaction.guild.id},${result.id})`,
function(err,result,fields){
if(err) {
interaction.reply('An Error Occurred: While trying to add the channels to the database.')
console.error(err)
}
else interaction.reply('Setup Completed');
});
});
appreciate any help
7 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Svitkona
Svitkona6mo ago
what makes you think that?
Mikey
MikeyOP6mo ago
this error
Error: Unknown column 'undefined' in 'field list'
at Packet.asError (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packets\packet.js:728:17)
at Query.execute (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:481:34)
at PacketParser.onPacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:97:12)
at PacketParser.executeStart (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:104:25)
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5) {
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
sqlMessage: "Unknown column 'undefined' in 'field list'",
**notice how it says undefined VVV**
sql: 'INSERT INTO `ServerSettings` (`serverID`, `guildsCategory`) VALUES (1258174553117687908,undefined)'
}
Error: Unknown column 'undefined' in 'field list'
at Packet.asError (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packets\packet.js:728:17)
at Query.execute (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:481:34)
at PacketParser.onPacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:97:12)
at PacketParser.executeStart (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:104:25)
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5) {
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
sqlMessage: "Unknown column 'undefined' in 'field list'",
**notice how it says undefined VVV**
sql: 'INSERT INTO `ServerSettings` (`serverID`, `guildsCategory`) VALUES (1258174553117687908,undefined)'
}
the result.id does give something from what it seems but it just says its undefined
Svitkona
Svitkona6mo ago
could you log result in the .then handler and show the output?
Mikey
MikeyOP6mo ago
it shows the id
Error: Unknown column 'undefined' in 'field list'
at Packet.asError (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packets\packet.js:728:17)
at Query.execute (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:481:34)
at PacketParser.onPacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:97:12)
at PacketParser.executeStart (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:104:25)
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5) {
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
sqlMessage: "Unknown column 'undefined' in 'field list'",
sql: 'INSERT INTO `ServerSettings` (`serverID`, `guildsCategory`) VALUES (1258174553117687908,undefined)'
}
* VVV
1259248381344354357
Error: Unknown column 'undefined' in 'field list'
at Packet.asError (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packets\packet.js:728:17)
at Query.execute (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:481:34)
at PacketParser.onPacket (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:97:12)
at PacketParser.executeStart (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (d:\NewDesktop\emberfall\Discord_Bot\node_modules\mysql2\lib\connection.js:104:25)
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5) {
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
sqlMessage: "Unknown column 'undefined' in 'field list'",
sql: 'INSERT INTO `ServerSettings` (`serverID`, `guildsCategory`) VALUES (1258174553117687908,undefined)'
}
* VVV
1259248381344354357
Svitkona
Svitkona6mo ago
err, what version of djs is this?
Mikey
MikeyOP6mo ago
14.15.3 ty goodsir :prayge: needed to mark the above function as async and set it to await
Want results from more Discord servers?
Add your server