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?
20 Replies
- 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!How can I call it?
if not?
like this? Or perhaps I am misunderstanding something
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).like this? Ahhh, not work
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)) ...
I try. But still not work
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(...)
I'm checking on my second account, however, unfortunately, the bot still doesn't leave the server.
is there no error in the console?
maybe add an
await
?
await interaction.guild.leave().then(...)
-
your function needs to be async
Can pls give some examples?
add
async
before interaction
:
client.on("", async interaction => ...)
still not work(
doesn't need the
async
or await
keyword if they're resolving promises with .then()
Are there any errors?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?
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
By Code & DB