3 回答

TA貢獻1829條經驗 獲得超7個贊
客戶端.users 其唯一的緩存用戶由客戶端。因此,如果重新啟動機器人,則此集合將為空。需要向機器人發送消息或將消息發送到機器人可以處理此消息以緩存在此集合中的通道。按照你的方式,如果你在公會上運行這個命令,或者如果這個用戶是你的公會的成員,你可以使用或嘗試通過ID獲得公會,然后在這個公會中通過他的ID獲取用戶。guild.members.cache.get('ID HERE')
一些例子:
var i;
var d = new Date;
var month = d.getMonth() + 1;
var day = d.getDate();
const s = await Tags.count();
if (message.member.hasPermission('KICK_MEMBERS')) {
}
for (i = 1; i <= s; i++) {
const tag = await Tags.findOne({
where: {
key: i
}
});
if (tag) {
var date = tag.get('description');
let useralert = (tag.get("usernameid")).toString();
let useralertID = useralert.replace(/[<@>]/g, '');
let deadday = parseInt(date.slice(0, 2));
let deadmonth = parseInt(date.slice(3, 5));
let dayn = deadday - day;
let monthn = deadmonth - month;
console.log(dayn.toString() + ' ' + monthn.toString() + ' ' + useralertID);
if (((dayn <= 2) && (monthn == 0)) || (monthn < 0)) {
let user = message.guild.members.cache.get(useralertID);
if (user) {
user.send('Works!').then(() => {
return message.channel.send(`Sent msg to ${user.username}!`);
}).catch(() => {
return message.channel.send(`${user.username} not allow to send DM message!`);
})
} else {
return message.channel.send(`the ${useralertID} not guild Member, can\`t send DM to him`);
}
}
}
}

TA貢獻1836條經驗 獲得超4個贊
發生錯誤的原因是 不存在或為 null。也許試試.
我真的不能再幫你了,因為你沒有告訴我們你想做什么。user
bot.users.cache.get("YOURIDHERE").send("hi")

TA貢獻2019條經驗 獲得超9個贊
好吧,問題是用戶是未定義的,就像內部和錯誤說的那樣,
let user = bot.users.cache.get('useralertID')
您在此處使用的是字符串而不是變量useralertID
無論如何,你應該檢查用戶是否存在,因為你是從間接的東西中提取id,不確定是什么。Tags
添加回答
舉報