How can I make it so that when users are blocked from accessing the bot, it leaves their server?

I read the Guide where it's explained how to block access to the bot for a specific user. But is there a reverse possibility where, if the owner is blocked from accessing the bot, the bot leaves their server?
No description
20 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
ofseal
ofsealOP7mo ago
How can I call it?
if (blockUser === OwnerID) {
guild.leave();
}
if (blockUser === OwnerID) {
guild.leave();
}
if not?
ofseal
ofsealOP7mo ago
like this? Or perhaps I am misunderstanding something
No description
Gabriel
Gabriel7mo ago
Upon entering a guild or when the bot receives the interactionCreate, you can check whenever or not the owner of the guild is blocked or not. You need the Guild object in order to get the owner's ID to leave the server, you can use guild.leave(). that's exactly what you've found. if you don't have the guild, then you can't fetch data or use the .leave() method (or any other one).
ofseal
ofsealOP7mo ago
like this? Ahhh, not work
No description
Gabriel
Gabriel7mo ago
in this case, you're checking if the user that ran the command is blocked you can access the guild obj via interaction.guild, so that would be if (blockedUsers.includes(interaction.guild.ownerId)) ...
ofseal
ofsealOP7mo ago
I try. But still not work
No description
Gabriel
Gabriel7mo ago
how exactly do you check if it works or not? also there's another mistake: the variable guild is no where to be found? you should use interaction.guild.leave().then(...)
ofseal
ofsealOP7mo ago
I'm checking on my second account, however, unfortunately, the bot still doesn't leave the server.
No description
Gabriel
Gabriel7mo ago
is there no error in the console? maybe add an await? await interaction.guild.leave().then(...)
ofseal
ofsealOP7mo ago
No description
ofseal
ofsealOP7mo ago
-
Gabriel
Gabriel7mo ago
your function needs to be async
ofseal
ofsealOP7mo ago
Can pls give some examples?
Gabriel
Gabriel7mo ago
add async before interaction: client.on("", async interaction => ...)
ofseal
ofsealOP7mo ago
still not work(
Kevinnnn
Kevinnnn7mo ago
doesn't need the async or await keyword if they're resolving promises with .then() Are there any errors?
ofseal
ofsealOP7mo ago
In console — nothing. But not work . How can I make it so that if a user is on the blacklist, the bot automatically leaves their server? Or it's work only when block user use bot?
Svitkona
Svitkona7mo ago
for example, you could periodically run code that loops through all the guilds, checks if the owner is blacklisted, and leave if so this is outside the scope of the library though, it's something you'd have to do yourself
ofseal
ofsealOP7mo ago
By Code & DB
const blockedUsers = ['1236176808861372480'];
client.on('interactionCreate', async interaction => {
if (blockedUsers.includes(interaction.guild.ownerId)) interaction.guild.leave().then(guild => console.log(`Left the guild: ${guild.name}`))
.catch(console.error);});
const blockedUsers = ['1236176808861372480'];
client.on('interactionCreate', async interaction => {
if (blockedUsers.includes(interaction.guild.ownerId)) interaction.guild.leave().then(guild => console.log(`Left the guild: ${guild.name}`))
.catch(console.error);});
Want results from more Discord servers?
Add your server