[英]How do I send the result of my MySQL Query?
我正在开发一个带有 discordjs 和 mysql 的 Discord Bot,我想问一下如何将我的查询结果发送给请求它的用户。 我的代码如下所示:如果您有任何解决方案或想法,请与我分享。 (我在顶部删除了一点代码)
const conn = mysql.createConnection({
host: "/",
user: "/",
password: "/",
database: "/"
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const { commandName } = interaction;
if (commandName === 'submit') {
conn.query(`INSERT INTO discordtest(userID, tag) VALUES ('${interaction.user.id}' , '${interaction.user.tag}')`)
await interaction.reply(':white_check_mark: Daten erfolgreich hinterlegt!');
interaction.channel.send({ embeds: [exampleEmbed] });
}
else if(commandName === 'info'){
conn.query(`SELECT licenses FROM discordtest WHERE userID=${interaction.user.id}`, (err, msg) =>{
var message = msg.content;
if(err){
console.log(err)
}else
console.log(msg)
});
const infoEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Webseite')
.setURL('https://zockercraft.de/')
.setAuthor({ name: 'User Info', iconURL: 'https://zockercraft.de/discordbild/bild.jpg'})
.setDescription(`Hier sind die Daten zu ${interaction.user.tag}:`)
.setThumbnail(interaction.user.avatarURL())
.addFields(
{ name: 'Test', value: 'test' , inline: true },
{ name: 'Test', value: 'Some value here', inline: true },
)
.setTimestamp()
.setFooter({ text: 'Designed by: DerBZocker2#9955'
});
await interaction.reply({ embeds: [infoEmbed] });
}
});```
conn.query(`SELECT licenses FROM discordtest WHERE userID='${interaction.user.id}'`, (err, msg) => {
var message = msg.content; //What is this for?
if(err) {
console.log(err)
} else {
const embed = new EmbedBuilder()
.setDescription(`${msg.userID}`) //msg will give you the details
//of your informations. connecting with '.' then add 'userID'
.setColor(0x0099FF)
.setTitle('Webseite')
await interaction.reply({ embeds: [infoEmbed] });
}
});
我对交互命令只有一点了解。 但我认为你只需要获取数据。 所以它应该做的伎俩
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.