我只会发布导致我出错的代码部分。
当我运行机器人时,它大约需要3秒钟的时间,并且机器人因我下面的错误而崩溃。
如果它有助于解决错误,该机器人是支持用户的票证机器人,它包含对表情符号的反应,并且该机器人创建了一个具有权限和消息的房间,您可以关闭票证和该房间已被删除。
const discord = require('discord.js');
const client = new discord.Client();
const config = require('./config.json');
var userTickets = new Map();
client.login(config.token);
client.on('ready', () => {
console.log(client.user.username + " has logged in.");
client.user.setPresence( {
status: "online",
game: {
name: "Tickets",
type: "WATCHING"
}
})
});
// code
client.on('message', message => {
if(message.author.bot) {
if(message.embeds.length === 1 && message.embeds[0].description.startsWith('Reacc')) {
message.react(idemoji1).then( () => message.react(idemoji2)).then( () => message.react(idemoji3))
.then(msgReaction => console.log('reacted'))
.catch(err => console.log(err));
}
if(message.embeds.length === 1 && message.embeds[0].description == '¡Gracias por crear el ticket!\nEl soporte se pondrá en contacto contigo lo antes posible.\n\nPor favor, responde las preguntas que se te hacen a continuación para poder date el mejor soporte.\n\n Si no escribes nada, el ticket se cerrará en 2 horas.\n\nPara cerrar este ticket reacciona a ?') {
message.react(emoji5)
.then(reaction => console.log("A reaccionado con " + reaction.emoji.name))
.catch(err => console.log(err));
}
};
控制台错误:
C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\ticketbot-reaction.js:43
if(message.embeds.length === 1 && message.embeds[0].description.startsWith('Reacc')) {
^
TypeError: Cannot read property 'startsWith' of undefined
at Client.<anonymous> (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\ticketbot-reaction.js:43:73)
at Client.emit (events.js:315:20)
at MessageCreateHandler.handle (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\nilma\Documents\Discord Bots\Discord-Ticket-Psyco\node_modules\ws\lib\websocket.js:789:20)
at Receiver.emit (events.js:315:20)