Javascript Discord Bot无法使用startWith()找到频道
我已经尝试了太长的时间来让这个代码工作,如果有人可以帮助我,将不胜感激Javascript Discord Bot无法使用startWith()找到频道,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我已经尝试了太长的时间来让这个代码工作,如果有人可以帮助我,将不胜感激 module.exports={ 配置:{ 名称:“关闭”, 描述:“关闭您已解决的问题。”, 用法:“-close”, 类别:“门票”, 可访问者:“成员” }, 运行:异步(消息)=>{ if(message.channel.name.startsWith('ticket-')){ 试一试{ message.channel.delete(); }捕获(e){ 控制台日志(e) } } } } 这会在此处产生一个错误:
module.exports={
配置:{
名称:“关闭”,
描述:“关闭您已解决的问题。”,
用法:“-close”,
类别:“门票”,
可访问者:“成员”
},
运行:异步(消息)=>{
if(message.channel.name.startsWith('ticket-')){
试一试{
message.channel.delete();
}捕获(e){
控制台日志(e)
}
}
}
}
这会在此处产生一个错误:
(node:25380) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined
at Object.run (/commands/tickets/close.js:10:29)
at module.exports (/events/guild/message.js:35:33)
at Client.emit (events.js:189:13)
at MessageCreateHandler.handle (/Desktop/waterhack bot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/Desktop/waterhack bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/Desktop/waterhack bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/Desktop/waterhack bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/Desktop/waterhack bot/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:189:13)
at Receiver.receiverOnMessage (/Desktop/waterhack bot/node_modules/ws/lib/websocket.js:789:20)
(node:25380) 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(). (rejection id: 5)
message.channel.name在我的其他代码中运行良好,但现在,当我只想删除一个频道时,它将不起作用,有什么线索可以解决这个问题吗
我已尝试通过获取作者名称来查找频道的确切名称,但message.author.username似乎也未定义,如果支持成员希望关闭它,这仍然无法工作。传递消息参数时可能出错。您可能需要检查您是否使用正确的变量进行了命令调用。您能告诉我们您是如何调用run函数的吗?我对自己感到非常恼火,我所要添加的只是
run:async(bot,message)
,它决定工作。很高兴我能帮助您完成这一步;)