得到了一个与旧命令处理程序一起使用的票证命令,我编辑了代码以使其与 DiscordJS Commando v12.5 一起使用,它说TypeError: Cannot read property 'on' of null
,代码中只有一个地方我说'on'
的是反应侦听器。这是代码:
const Commando = require('discord.js-commando')
const Discord = require('discord.js')
const channelId = '873769980729106442'
const thumbsup = ''
const thumbsdown = ''
let registered = false
const registerEvent = client => {
if (registered) {
return
}
registered = true
client.on('messageReactionAdd', (reaction, user) => {
if (user.bot) {
return
}
const { message } = reaction
if (message.channel.id === channelId) {
message.delete()
}
})
}
module.exports = class TicketCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'ticket',
group: 'misc',
memberName: 'ticket',
description: 'Sends a suggestion to the staff',
})
}
run(userMessage, args, text, client) {
const { guild, member } = userMessage
const syntax = `${guild.commandPrefix}ticket <Message>`
registerEvent(client)
const channel = guild.channels.cache.get(channelId)
const newTicketEmbed = new Discord.MessageEmbed()
.setAuthor(userMessage.author.username)
.setTitle('SUCCESS\n\nCreated a new ticket: ')
.setDescription(`"${text}"`)
.setFooter(`Click the ${thumbsup} icon to delete this message.`)
.setColor('#1be730')
channel.send(newTicketEmbed).then(ticketMessage => {
ticketMessage.react(thumbsup).then(() => {
ticketMessage.react(thumbsdown)
})
const replyEmbed = new Discord.MessageEmbed()
.setTitle('SUCCESS')
.setDescription(`<@${member.id}> Your ticket has been created!\n\n**${args.join(' ')}**`)
.setFooter('While the community votes, expect a reply from staff soon!')
.setColor('#1be730')
userMessage.channel.send(replyEmbed).then((newMessage) => {
newMessage.react(thumbsup).then(() => {
newMessage.react(thumbsdown)
})
})
userMessage.delete()
})
}
}
在与 Commando 一起使用之前,该代码运行良好。