-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto db push for guilds #819
Comments
Hello, has anyone seen this? Would really help with slash commands not working after system changed and/or DB loss |
Will someone please have a look at this? Would solve all of the problems that I'm facing if it were added. |
Could someone at least give me a starting point to fix it myself? It's really annoying |
That would be done via the bot start event emitter. /*
* client is your discord.js Client
* commands obj is your command data you want to add to the guild
*/
client.on('ready', async (guild) => {
guild.commands.set(commands).then(() =>
console.log(`Commands deployed in guild ${guild.name}!`));
}) Naturally, it would need to be adjusted for this bot's code. But, that's the general idea of how it would be done the easiest. Might also be a good idea to have some sort of check in there to prevent from updating anything that hasn't changed. |
Ah alright, thanks for the starting point, will comment here again if I've got it working |
It looks like for this bot you might just need to add this to the ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(
RegisterBehavior.BulkOverwrite
); So, basically the ready event in the client.on('ready', async () => {
client.music.connect(client.user!.id);
client.user?.setActivity('/', {
type: ActivityType.Watching
});
client.user?.setStatus('online');
const token = client.twitch.auth.access_token;
if (!token) return;
// happens to be the first DB call at start up
try {
const notifyDB = await trpcNode.twitch.getAll.query();
const query: string[] = [];
for (const user of notifyDB.notifications) {
query.push(user.twitchId);
client.twitch.notifyList[user.twitchId] = {
sendTo: user.channelIds,
logo: user.logo,
live: user.live,
messageSent: user.sent,
messageHandler: {}
};
}
await notify(query).then(() =>
setInterval(async () => {
const newQuery: string[] = [];
// pickup newly added entries
for (const key in client.twitch.notifyList) {
newQuery.push(key);
}
await notify(newQuery);
}, 60 * 1000)
);
} catch (err) {
Logger.error('Prisma ' + err);
}
}); to this: client.on('ready', async () => {
ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(
RegisterBehavior.Overwrite
);
client.music.connect(client.user!.id);
client.user?.setActivity('/', {
type: ActivityType.Watching
});
client.user?.setStatus('online');
const token = client.twitch.auth.access_token;
if (!token) return;
// happens to be the first DB call at start up
try {
const notifyDB = await trpcNode.twitch.getAll.query();
const query: string[] = [];
for (const user of notifyDB.notifications) {
query.push(user.twitchId);
client.twitch.notifyList[user.twitchId] = {
sendTo: user.channelIds,
logo: user.logo,
live: user.live,
messageSent: user.sent,
messageHandler: {}
};
}
await notify(query).then(() =>
setInterval(async () => {
const newQuery: string[] = [];
// pickup newly added entries
for (const key in client.twitch.notifyList) {
newQuery.push(key);
}
await notify(newQuery);
}, 60 * 1000)
);
} catch (err) {
Logger.error('Prisma ' + err);
}
}); That should fix it if I'm not mistaken. There might be some indentation errors, however, since I made that edit entirely from GitHub mobile. |
Thinking about this a bit more. It might be better to have a command that updates all commands and then restarts the bot to load the changes in every guild. |
Hmm alright, I can try to do that |
Explain your suggestion
I wish that it would automatically check for guilds the bot is in when started and update the database accordingly so I don't have to kick and re-invite the bot to get slash commands to work for every server it's in
The text was updated successfully, but these errors were encountered: