【发布时间】:2021-04-26 04:59:17
【问题描述】:
当我的机器人加入服务器时,我试图让它向特定公会的频道发送消息,代码如下:
client.on('guildCreate', guild => {
guild.systemChannel.send('Thank you for adding Optic to your server. Run ``-help`` to view a full list of commands')
const server = client.guilds.cache.find(myserverId)
const channel = server.channels.cache.get(channelId)
const joinEmbed = new Discord.MessageEmbed()
.setTitle("Joined")
.setDescription("Optic was added to a server")
.addFields(
{ name: 'GuildId', value: guild.id,inline: false },
{ name: 'Name', value: guild.name, inline: false },
{ name: 'Guild OwnerId', value: guild.ownerID, inline: false },
)
channel.send(joinEmbed)
});
然后它发送这个错误:
UnhandledPromiseRejectionWarning: TypeError: fn is not a function
at Map.find (/app/node_modules/@discordjs/collection/dist/index.js:161:17)
at Client.<anonymous> (/app/main.js:118:38)
at Client.emit (events.js:314:20)
at Object.module.exports [as GUILD_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/GUILD_CREATE.js:33:14)
at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:314:20)
at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:825:20)
(node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我检查了docs for it,我认为我使用正确。我还删除了 guildId 和 channelId 但它们在实际代码中。 谢谢
【问题讨论】:
标签: node.js discord discord.js