Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何提及使用Chat Discord.JS发送消息的用户?_Javascript_Discord_Discord.js - Fatal编程技术网

Javascript 如何提及使用Chat Discord.JS发送消息的用户?

Javascript 如何提及使用Chat Discord.JS发送消息的用户?,javascript,discord,discord.js,Javascript,Discord,Discord.js,对不起,英语不是我的母语,我是JS新手。 我正在使我的机器人不和谐,我需要它发送随机消息在聊天在一段时间内,这部分我有下面的代码。 然而,我还需要机器人提到最后一个用户已经发送了聊天信息 我不知道如何将它添加到我的代码中 async function notifLoop(){ while(true){ client.channels.cache.get('764266751734054953').send("test text"); await Sleep

对不起,英语不是我的母语,我是JS新手。 我正在使我的机器人不和谐,我需要它发送随机消息在聊天在一段时间内,这部分我有下面的代码。 然而,我还需要机器人提到最后一个用户已经发送了聊天信息 我不知道如何将它添加到我的代码中

async function notifLoop(){
  while(true){
    client.channels.cache.get('764266751734054953').send("test text");
    await Sleep(10000)
  }
}

function Sleep(milliseconds) {
    return new Promise(resolve => setTimeout(resolve, milliseconds));
}

client.on('ready', function(){
    notifLoop();
    console.log("Ready");
});

我需要它在一段时间内发送聊天中的随机消息

)


我还需要机器人提到的最后一个用户已经发送了聊天信息

您可以使用和的组合。首先,必须使用
MessageManager.fetch()
获取频道中的最后一条消息。此函数返回一组消息,您只需要其中的第一条消息(当您在通道中获取第一条消息时)

在本文的第一部分中,您可以从user/GuildMember对象中找到一系列提及用户的方法

异步函数notifLoop(){ const channel=client.channels.cache.get('764266751734054953'); while(true){ const user=channel.messages .fetch({limit:1}) .then((msg)=>channel.send(`user was`); 等待睡眠(10000); } } 您可以使用此选项提及用户:

你也可以用这个:

message.reply(``);
message.reply(`message.author}`)
实际上会返回
@E3saR,@E3saR
  message.reply(`${message.author}`);
  message.reply(`<@${message.author.id}>`);