当我测试我的命令时,我遇到了一个错误,我已经尝试过多次修复,但我仍然无法让它工作。 这是公告代码:
const { MessageEmbed } = require("discord.js")
exports.run = async(client, msg, args) => {
if(!msg.member.hasPermission('MANAGE_MESSAGES')) return msg.reply('You can\'t use that!');
const channel = msg.mentions.channels.first() || msg.guild.channels.cache.find(c => c.id === args[0])
if(!channel) return msg.reply("channel not found!")
const announcement = args.slice(1).join(" ")
if(!announcement) return msg.reply("Please give an announcement")
var embed = new MessageEmbed()
.setColor("BLUE")
.setTitle("Announcement!")
.setDescription(`**${announcement}**`)
.setFooter(msg.auther.displayAvaterURL, msg.auther.tag({ dynamic: true}))
channel.send(embed)
}
没有页脚一切正常,但我想把它放进去。 这是我得到的错误:
(node:8976) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tag' of undefined
at Object.exports.run (D:\spil\Firlingdon & xEpic_Wolf Bot\commands\announce.js:12:27)
at Client.<anonymous> (D:\spil\Firlingdon & xEpic_Wolf Bot\index.js:28:14)
at Client.emit (events.js:387:35)
at MessageCreateAction.handle (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (D:\spil\Firlingdon & xEpic_Wolf Bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:375:28)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8976) 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:8976) [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.
当我切换 displayAvaterURL 时, 它只是替换为:
TypeError: Cannot read property 'displayAvaterURL'
答案 0 :(得分:1)
试试这个:
const { MessageEmbed } = require("discord.js")
exports.run = async (client, msg, args) => {
if (!msg.member.hasPermission("MANAGE_MESSAGES")) return msg.reply("You can't use that!")
const channel =
msg.mentions.channels.first() || msg.guild.channels.cache.find((c) => c.id === args[0])
if (!channel) return msg.reply("channel not found!")
const announcement = args.slice(1).join(" ")
if (!announcement) return msg.reply("Please give an announcement")
var embed = new MessageEmbed()
.setColor("BLUE")
.setTitle("Announcement!")
.setDescription(`**${announcement}**`)
.setFooter(message.author.tag,message.author.avatarURL({ dynamic: true }))
channel.send(embed)
}