fix dm channel grabbing

This commit is contained in:
Cynthia Foxwell 2023-01-21 21:52:07 -07:00
parent 3be78312e1
commit c9faaab317
2 changed files with 6 additions and 5 deletions

View file

@ -72,7 +72,7 @@ bot.once("ready", async () => {
logger.info("hf:main", "Connected to Discord."); logger.info("hf:main", "Connected to Discord.");
logger.info("hf:main", `Logged in as: ${bot.user.tag} (${bot.user.id})`); logger.info("hf:main", `Logged in as: ${bot.user.tag} (${bot.user.id})`);
const channel = await bot.users.get(config.owner_id)?.createDM(); const channel = await bot.getDMChannel(config.owner_id);
if (channel) { if (channel) {
channel.createMessage({ channel.createMessage({
content: "<:ms_tick:503341995348066313> Loaded HiddenPhox.", content: "<:ms_tick:503341995348066313> Loaded HiddenPhox.",

View file

@ -20,6 +20,7 @@ if (!fs.existsSync(resolve(__dirname, "..", "..", "private_reminders.json")))
return; return;
const tzFormatterCache = {}; const tzFormatterCache = {};
const dmCache = {};
const reminderData = require(resolve( const reminderData = require(resolve(
__dirname, __dirname,
@ -83,7 +84,10 @@ hf.bot.once("ready", () => {
}); });
} }
const channel = await hf.bot.users.get(data.user)?.createDM(); if (!dmCache[data.user]) {
dmCache[data.user] = await hf.bot.getDMChannel(data.user);
}
const channel = dmCache[data.user];
const [date, time] = tzFormatterCache[data.tz] const [date, time] = tzFormatterCache[data.tz]
.format(Date.now()) .format(Date.now())
@ -103,9 +107,6 @@ hf.bot.once("ready", () => {
content: ":alarm_clock: " + data.message, content: ":alarm_clock: " + data.message,
}); });
await setLastRun(data.user, date); await setLastRun(data.user, date);
logger.verbose("privateReminders", "successfully sent");
} else {
logger.verbose("privateReminders", "dm channel is null");
} }
} }
} }