[英]Discord.js embed not refreshing
所以我創建了一個命令info
來顯示機器人的信息,這是我的代碼( 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);
這是info.json
:
{
"userTag": "NutronStar45's Bot or Whatever#3786",
"appId": "823538828161581096",
"publicKey": "df3c6f58c4c7aeed050d7f2048c6c35061b3a67838e1090280c89a82aba8a431",
"clientId": "823538828161581096"
}
這是auth.json
:
{
"clientSecret": "********************************",
"token": "***********************************************************"
}
我在main.js
中使用節點外部 cmd 啟動 main.js,我將+ns info
發送到我測試我的機器人的服務器,一切看起來都很正常,但是第三個嵌入的字段完全錯誤。
我用相同的字段測試了機器人的嵌入,但似乎嵌入中的字段已被 Discord.py 或 Discord 保存,我猜是緩存。
所以我創建了一個命令info
來顯示機器人的信息,這是我的代碼( 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);
這是info.json
:
{
"userTag": "NutronStar45's Bot or Whatever#3786",
"appId": "823538828161581096",
"publicKey": "df3c6f58c4c7aeed050d7f2048c6c35061b3a67838e1090280c89a82aba8a431",
"clientId": "823538828161581096"
}
這是auth.json
:
{
"clientSecret": "********************************",
"token": "***********************************************************"
}
我在main.js
中使用節點外部 cmd 啟動 main.js,我將+ns info
發送到我測試我的機器人的服務器,一切看起來都很正常,但是第三個嵌入的字段完全錯誤。
我用相同的字段測試了機器人的嵌入,但似乎嵌入中的字段已被 Discord.py 或 Discord 保存,我猜是緩存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.