我正在尝试使我的机器人具有DM命令,该命令可以向特定用户发送特定DM消息。
例如:
我:!dm @ user#6969嗨,你是谁
Bot:向用户#6969发送消息“你好,你好吗”
当前使用Visual Studio Code编写代码,由于无法真正找到有效的教程,我不知道如何执行此命令。
if(message.content.startsWith(`${prefix}dm`)) {
var mention = message.mentions.members.first()
mention.send("hi")
}
这是错误:
mention.send("hi")
^
TypeError: Cannot read property 'send' of undefined
at Client.client.on.message (/Users/Private/Desktop/Discord/bot/index.js:69:17)
at Client.emit (events.js:198:13)
at MessageCreateHandler.handle (/Users/Private/Desktop/Discord/bot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/Users/Private/Desktop/Discord/bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/Users/Private/Desktop/Discord/bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/Users/Private/Desktop/Discord/bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/Users/Private/Desktop/Discord/bot/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnMessage (/Users/Private/Desktop/Discord/bot/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:198:13)```
答案 0 :(得分:0)
if(message.content.startsWith(`${prefix}dm`)) {
const mentionedUser = message.mentions.users.first();
if(!mentionedUser) return message.reply('Mention Somebody');
mentionedUser.send('Hi');
}