我正在制作一个 Discord 机器人,让您可以使用“!dm”命令。我正在努力做到这一点,每当有人使用“!dm”命令,放置用户ID/提及用户,并放置一条消息时,它都会向提到的用户/用户ID发送消息。这是我的代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
<div class="col-md-12"><strong>subject</strong></div>
<div id="lessText" class="disp-cont col-md-auto">
Lorem Ipsum is simply dummy text of the printing an
</div>
<div id="moreText" class="more-cont col-md-auto" style="display:none;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s
</div>
<a href="#" class="more col-md-auto">read more</a>
<div class="col-md-12">no record</div>
</div>
答案 0 :(得分:0)
集合 client.users.cache.get()
是由 id 映射的,所以它应该是 client.users.cache.get(taggedUser.id);
。但是,一个更大的问题是,您将客户称为 bot
而不是 client
,这就是 client.users.cache.get()
不起作用的原因。完整代码应如下所示:
bot.on('message', (message) => {
if (message.content === '!dm') {
const taggedUser = message.mentions.users.first();
const user = bot.users.cache.get(taggedUser.id);
user.send('test');
}
});
确保你记住你对变量的称呼!
答案 1 :(得分:0)
const target = message.mentions.users.first()
if(!target) return message.reply('You Didnt State the User you want to send the dm to')
const msgs = args[1]
if(!msgs) return message.reply('You Didnt State the Message you want to send the user')
if(message.attachments.size > 0){
var Attachment = message.attachments.array();
var OurAttachment = Attachment[0];
const attachment = new MessageAttachment(OurAttachment.url);
target.send(msgs);
target.send(attachment);
message.channel.send('Sent a Dm to ' + target.username)
} else {
target.send(msgs);
message.reply('Sent a Dm to ' + target.username)
}