如何让我的 Discord js Bot 检查是否有人正在输入 bot dms?
How do I make my Discord js Bot check if someone is typing in the bots dms?
我想让我的机器人检查是否有人在机器人 dms 中输入。我该怎么做?
Client.on("typingStart", async function(channel, user){
console.log(channel)
console.log(user)
if(channel.type == "dm"){
console.log("one")
while(user.typing){
console.log("two")
Sleep(2000)
}
}
})
看来您遇到的问题与 here 所述的问题相同。从那里它指出:
The event can only emit on client if the channel is cached, discord.js otherwise drops the event (does not emit it). In this case this means you did not have a DM during the bots session from either side (you -> bot/ bot- > you), else the channel would be created/cached.
您可以通过在 client
中启用 partials
来解决这个问题,但它在 documentation 中指出: partials 要求您在以下情况下进行检查处理数据.
话虽如此,您可以简单地用此替换您的 Client
声明,以便为 DM 发出事件:
const Client = new Discord.Client({
partials: ["CHANNEL", "USER"]
});
我想让我的机器人检查是否有人在机器人 dms 中输入。我该怎么做?
Client.on("typingStart", async function(channel, user){
console.log(channel)
console.log(user)
if(channel.type == "dm"){
console.log("one")
while(user.typing){
console.log("two")
Sleep(2000)
}
}
})
看来您遇到的问题与 here 所述的问题相同。从那里它指出:
The event can only emit on client if the channel is cached, discord.js otherwise drops the event (does not emit it). In this case this means you did not have a DM during the bots session from either side (you -> bot/ bot- > you), else the channel would be created/cached.
您可以通过在 client
中启用 partials
来解决这个问题,但它在 documentation 中指出: partials 要求您在以下情况下进行检查处理数据.
话虽如此,您可以简单地用此替换您的 Client
声明,以便为 DM 发出事件:
const Client = new Discord.Client({
partials: ["CHANNEL", "USER"]
});