当机器人由服务器托管时发送嵌入消息时出错
Error when sending a embed message when the bot is hosted by a server
(node:24) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
有人知道如何在服务器上托管机器人时解决这个错误吗?因为当新用户加入 disord 服务器时会出现错误,通常机器人会发送嵌入的 dm 欢迎消息,但现在它只给我这个错误,当我在我的电脑上启动机器人时,它工作得很好,当我使用非嵌入版本时,它也可以在服务器上工作,所以它与嵌入消息有关。
我的整个代码顺便说一句:
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Ready!');
client.user.setPresence({ activity: { name: 'with servers!' }, status: 'online' })
})
client.on("guildMemberAdd", member => {
try {
const Embed = {
color: 0x0099ff,
title: 'Welcome!',
url: 'https://potatohost.cc',
description: 'We offer Budget Minecraft, Minecraft Bedrock, Rust, Deticated Servers, Discord Bot and VPS Servers. We also sell domains and web designs!',
thumbnail: {
"url": 'attachment://ironnode.png',
},
fields: [
{
name: `Hey!`,
value: `I want to help you and so my question is: Do you want to buy a server or do you need more information first? \n
A: I want to buy a server
B: I need more information first \n
Please react to this message with A or B.`,
},
],
image: {
url: "attachment://ironnode.png",
},
timestamp: new Date(),
footer: {
text: 'Have a great time!',
icon_url: "attachment://ironnode.png",
},
};
member.send({ embed: Embed, files: [{
attachment:'/home/container/ironnode.png',
name:'ironnode.png'
}] })
.then(function (message) {
message.react("")
message.react("")
const filter = (reaction, user) => {
return ['', ''].includes(reaction.emoji.name) && user.id === member.id;
};
message.awaitReactions(filter, { max: 1 })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '') {
const Embed = {
color: 0x0099ff,
description: 'Ok, so you want to buy a server. Let me recommend you to create a ticket in <#700601793750499348>.',
};
message.channel.send({ embed: Embed })
}
else {
const Embed = {
color: 0x0099ff,
description: 'Ok, so you need more information first. Let me recommend you to visit <#700610172879634472>.',
};
message.channel.send({ embed: Embed })
}
})
});
}catch (err) {
console.log(err)
}
})
client.on('message', message => {
if (message.content === `${prefix}ping`) {
message.channel.send('Pong.');
}
});
client.login(token);
确保您的 NodeJS 版本高于 v12:https://nodejs.org/
(node:24) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
有人知道如何在服务器上托管机器人时解决这个错误吗?因为当新用户加入 disord 服务器时会出现错误,通常机器人会发送嵌入的 dm 欢迎消息,但现在它只给我这个错误,当我在我的电脑上启动机器人时,它工作得很好,当我使用非嵌入版本时,它也可以在服务器上工作,所以它与嵌入消息有关。
我的整个代码顺便说一句:
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Ready!');
client.user.setPresence({ activity: { name: 'with servers!' }, status: 'online' })
})
client.on("guildMemberAdd", member => {
try {
const Embed = {
color: 0x0099ff,
title: 'Welcome!',
url: 'https://potatohost.cc',
description: 'We offer Budget Minecraft, Minecraft Bedrock, Rust, Deticated Servers, Discord Bot and VPS Servers. We also sell domains and web designs!',
thumbnail: {
"url": 'attachment://ironnode.png',
},
fields: [
{
name: `Hey!`,
value: `I want to help you and so my question is: Do you want to buy a server or do you need more information first? \n
A: I want to buy a server
B: I need more information first \n
Please react to this message with A or B.`,
},
],
image: {
url: "attachment://ironnode.png",
},
timestamp: new Date(),
footer: {
text: 'Have a great time!',
icon_url: "attachment://ironnode.png",
},
};
member.send({ embed: Embed, files: [{
attachment:'/home/container/ironnode.png',
name:'ironnode.png'
}] })
.then(function (message) {
message.react("")
message.react("")
const filter = (reaction, user) => {
return ['', ''].includes(reaction.emoji.name) && user.id === member.id;
};
message.awaitReactions(filter, { max: 1 })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '') {
const Embed = {
color: 0x0099ff,
description: 'Ok, so you want to buy a server. Let me recommend you to create a ticket in <#700601793750499348>.',
};
message.channel.send({ embed: Embed })
}
else {
const Embed = {
color: 0x0099ff,
description: 'Ok, so you need more information first. Let me recommend you to visit <#700610172879634472>.',
};
message.channel.send({ embed: Embed })
}
})
});
}catch (err) {
console.log(err)
}
})
client.on('message', message => {
if (message.content === `${prefix}ping`) {
message.channel.send('Pong.');
}
});
client.login(token);
确保您的 NodeJS 版本高于 v12:https://nodejs.org/