So I created a command info
to show the info of the bot, here's my code ( main.js
):
const Discord = require('discord.js'); // Import the discord.js module
const client = new Discord.Client(); // Create an instance of a Discord client
const auth = require('./auth.json'); // The bot's secret
const info = require('./info.json'); // The bot's info
const inviteLink = 'https://discord.com/api/oauth2/authorize?client_id=823538828161581096&permissions=8&scope=bot'; // The bot's invite link
let prefix = '+ns'; // Initial prefix
let embeds = {
info: [
new Discord.MessageEmbed()
.setTitle('Help Center: Info')
.setColor(0x008dff)
.setDescription(`This is the help center of **${ info.userTag }**`)
.addField('Syntax', `${ prefix } info`, true)
.addField('Usage', 'Get the bot\'s info', true),
new Discord.MessageEmbed()
.setTitle('Info: Client')
.setColor(0xff0000)
.setDescription(`The client info of **${ info.userTag }**`)
.addField('App ID', info.appId, true)
.addField('Public key', info.publicKey, true)
.addField('Client ID', info.clientId, true),
new Discord.MessageEmbed()
.setTitle('Info: Links')
.setColor(0xff0000)
.setDescription(`Related links`)
.addField('Source code (GitHub)', '[NutronStar45/NutronStar45sDiscordBot](https://github.com/NutronStar45/NutronStar45sDiscordBot)', true)
.addField('Invite link', inviteLink, true),
new Discord.MessageEmbed()
.setTitle('Info: Attributes')
.setColor(0xff0000)
.setDescription(`The attributes of **${ info.userTag }**`),
new Discord.MessageEmbed()
.setTitle('Info: Statistics')
.setColor(0xff0000)
.setDescription(`The stats of **${ info.userTag }**`)
]
}; // Initial embeds
// Login
client.on('ready', () => {
console.log(`Client: Logged in as ${ client.user.tag }`)
});
// Set a listener to the message
client.on('message'. msg => {
if (msg.content == `${ prefix } info`) {
// Info
embeds.info.forEach(element == {
msg.channel.send(element);
});
}
});
client.login(auth.token);
And here's the info.json
:
{
"userTag": "NutronStar45's Bot or Whatever#3786",
"appId": "823538828161581096",
"publicKey": "df3c6f58c4c7aeed050d7f2048c6c35061b3a67838e1090280c89a82aba8a431",
"clientId": "823538828161581096"
}
Here's the auth.json
:
{
"clientSecret": "********************************",
"token": "***********************************************************"
}
I started the main.js
with node external cmd in vscode, I send +ns info
to the server which I test my bot, everything looks normal, but the 3rd embed's fields are completely wrong.
I tested the bot's embed with the same field, but it seems that the fields in the embed have been saved by Discord.py or Discord, I guess it's caching.
So I created a command info
to show the info of the bot, here's my code ( main.js
):
const Discord = require('discord.js'); // Import the discord.js module
const client = new Discord.Client(); // Create an instance of a Discord client
const auth = require('./auth.json'); // The bot's secret
const info = require('./info.json'); // The bot's info
const inviteLink = 'https://discord.com/api/oauth2/authorize?client_id=823538828161581096&permissions=8&scope=bot'; // The bot's invite link
let prefix = '+ns'; // Initial prefix
let embeds = {
info: [
new Discord.MessageEmbed()
.setTitle('Help Center: Info')
.setColor(0x008dff)
.setDescription(`This is the help center of **${ info.userTag }**`)
.addField('Syntax', `${ prefix } info`, true)
.addField('Usage', 'Get the bot\'s info', true),
new Discord.MessageEmbed()
.setTitle('Info: Client')
.setColor(0xff0000)
.setDescription(`The client info of **${ info.userTag }**`)
.addField('App ID', info.appId, true)
.addField('Public key', info.publicKey, true)
.addField('Client ID', info.clientId, true),
new Discord.MessageEmbed()
.setTitle('Info: Links')
.setColor(0xff0000)
.setDescription(`Related links`)
.addField('Source code (GitHub)', '[NutronStar45/NutronStar45sDiscordBot](https://github.com/NutronStar45/NutronStar45sDiscordBot)', true)
.addField('Invite link', inviteLink, true),
new Discord.MessageEmbed()
.setTitle('Info: Attributes')
.setColor(0xff0000)
.setDescription(`The attributes of **${ info.userTag }**`),
new Discord.MessageEmbed()
.setTitle('Info: Statistics')
.setColor(0xff0000)
.setDescription(`The stats of **${ info.userTag }**`)
]
}; // Initial embeds
// Login
client.on('ready', () => {
console.log(`Client: Logged in as ${ client.user.tag }`)
});
// Set a listener to the message
client.on('message'. msg => {
if (msg.content == `${ prefix } info`) {
// Info
embeds.info.forEach(element == {
msg.channel.send(element);
});
}
});
client.login(auth.token);
And here's the info.json
:
{
"userTag": "NutronStar45's Bot or Whatever#3786",
"appId": "823538828161581096",
"publicKey": "df3c6f58c4c7aeed050d7f2048c6c35061b3a67838e1090280c89a82aba8a431",
"clientId": "823538828161581096"
}
Here's the auth.json
:
{
"clientSecret": "********************************",
"token": "***********************************************************"
}
I started the main.js
with node external cmd in vscode, I send +ns info
to the server which I test my bot, everything looks normal, but the 3rd embed's fields are completely wrong.
I tested the bot's embed with the same field, but it seems that the fields in the embed have been saved by Discord.py or Discord, I guess it's caching.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.