Discord error 40007: User is banned from this guild
Last verified against Discord Developer Docs - Opcodes and status codes
The user is banned from this guildWhat error 40007 means
You tried to add a user to a guild (OAuth2 guilds.join via PUT /guilds/{guild.id}/members/{user.id}) who is currently banned there. Discord refuses the join until the ban is lifted. The bot's permissions are irrelevant; even with Administrator the join cannot proceed while the ban exists.
This is common in verification-gate and "join via website" flows: a user completes your OAuth2 login, your backend calls the add-member endpoint, and it fails because that user was banned from the server previously, sometimes years ago. The user may not even remember. Your UI should explain this rather than showing a generic failure.
What it looks like
{
"message": "The user is banned from this guild",
"code": 40007
}Why it happens
- User was banned from the target guild at some point and the ban was never removed
- Ban applied by another bot or moderator between the OAuth2 consent and the join call
- Wrong guild ID, adding the user to a server where they happen to be banned
How to fix Discord error 40007
- 1Check the ban first with GET /guilds/{guild.id}/bans/{user.id} (requires Ban Members); a 200 means banned, 404 means not banned
- 2If the ban should be lifted, DELETE /guilds/{guild.id}/bans/{user.id} and then retry the join
- 3Otherwise show the user a specific message ("you are banned from this server; contact its moderators")
- 4Confirm the guild ID is the intended server
How to stop it recurring
In any guilds.join flow, query the ban list before attempting the add and branch on the result, so the failure mode is a deliberate message rather than an exception. Log 40007 separately from other join failures so you can see how often it happens.
Provide moderators with a command that lists recent 40007 failures so they can decide whether to unban, and keep the user-facing copy free of detail that could be used to probe ban status of other accounts.
OAuth2 join flows should treat bans as a first-class outcome with dedicated copy, not an error state. The ban endpoints referenced above require Ban Members, whose absence produces 50013; if the user is not banned but simply unverified, the same join fails with 40002.
Official reference: Discord Developer Docs - Opcodes and status codes. See all Discord error codes or the Discord limits and quotas.
Related codes
Error 40007 - quick answers
What does Discord error 40007 mean?
You tried to add a user to a guild (OAuth2 guilds.join via PUT /guilds/{guild.id}/members/{user.id}) who is currently banned there. Discord refuses the join until the ban is lifted. The bot's permissions are irrelevant; even with Administrator the join cannot proceed while the ban exists.
How do I fix Discord error 40007?
1. Check the ban first with GET /guilds/{guild.id}/bans/{user.id} (requires Ban Members); a 200 means banned, 404 means not banned 2. If the ban should be lifted, DELETE /guilds/{guild.id}/bans/{user.id} and then retry the join 3. Otherwise show the user a specific message ("you are banned from this server; contact its moderators") 4. Confirm the guild ID is the intended server
Should I retry after error 40007?
No. Retrying the same request produces the same error; the condition has to be fixed first. Treat it as a permanent failure for that message and surface it, rather than looping.
Stop debugging Discord by hand
Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.