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 toolkit•6mo 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
ofseal•6mo ago
How can I call it?
if (blockUser === OwnerID) {
guild.leave();
}
if (blockUser === OwnerID) {
guild.leave();
}
if not?
ofseal
ofseal•6mo ago
like this? Or perhaps I am misunderstanding something
No description
Gabriel
Gabriel•6mo 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
ofseal•6mo ago
like this? Ahhh, not work
No description
Gabriel
Gabriel•6mo 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
ofseal•6mo ago
I try. But still not work
No description
Gabriel
Gabriel•6mo 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
ofseal•6mo ago
I'm checking on my second account, however, unfortunately, the bot still doesn't leave the server.
No description
Gabriel
Gabriel•6mo ago
is there no error in the console? maybe add an await? await interaction.guild.leave().then(...)
ofseal
ofseal•6mo ago
No description
ofseal
ofseal•6mo ago
-
Gabriel
Gabriel•6mo ago
your function needs to be async
ofseal
ofseal•6mo ago
Can pls give some examples?
Gabriel
Gabriel•6mo ago
add async before interaction: client.on("", async interaction => ...)
ofseal
ofseal•6mo ago
still not work(
Kevinnnn
Kevinnnn•6mo ago
doesn't need the async or await keyword if they're resolving promises with .then() Are there any errors?
ofseal
ofseal•6mo 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
Svitkona•6mo 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
ofseal•6mo 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