Reputation: 71
Ok so, I noticed that it's extremely easy to use a bot with Python on Discord, but it's not possible on Node JS? I mean, there must be a way to log in to a user account with Node JS, anybody know?
Whenever trying to log in to a user account with discord.js, it replies with this:
Error [TOKEN_INVALID]: An invalid token was provided.
I'm pretty curious; I'd like to make something that would react with "uwu" every time someone says "uwu".
Upvotes: 3
Views: 9026
Reputation: 61
User token support was removed after v11.6.4
.
It's the latest usable/semi-stable version that provides user token support...
So add "discord.js": "11.6.4",
to your package.json dependencies and have fun!
{
"dependencies": {
"discord.js": "11.6.4"
}
}
OR Just use one of the answers that these fine people provided (This is what I'm going to do)
Upvotes: 0
Reputation: 1
yesterday discord passing user's token for selfbots
import discord
import os
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
bot = commands.Bot(intents=discord.Intents.all(), command_prefix='>', self_bot=True)
@bot.event
async def on_ready():
print('#######################################')
print('Logged in as')
print(f"User : {bot.user.name}")
print(f"ID : {bot.user.id}")
print('########################################')
TOKEN = os.getenv("DISCORD_TOKEN")
bot.run(TOKEN)
** File "C:\Python311\Lib\site-packages\discord\http.py", line 805, in static_login raise LoginFailure('Improper token has been passed.') from exc discord.errors.LoginFailure: Improper token has been passed.**
Upvotes: -3
Reputation: 762
I guess they must have patched user botting on discord.js. I switched from 13.5.0
to an older version where it worked: 11.3.2
.
package.json
...
"dependencies": {
"discord.js": "^11.3.2",
...
Of course, if you need some feature introduced in a newer version, this solution may not work for you.
Upvotes: 0
Reputation: 56
You can use https://github.com/botkalista/discord.js.userbot
const Discord = require('discord.js');
const allowUserBotting = require('discord.js.userbot');
const client = new Discord.Client();
allowUserBotting(client);
client.login('YOUR USER TOKEN HERE');
Upvotes: 4
Reputation: 5330
Different libraries, different degrees of freedom. You observed it is not possible with discord.js but it is possible with discord.py.
Either use the Python library or you edit the JavaScript library.
headers: { Authorization: `Bot ${token.replace(/^Bot\s*/i, '')}` },
headers['Authorization'] = 'Bot ' + self.token if self.bot_token else self.token
The only difference between the two of them is the Authorization header. In discord.py when a Bot token is supplied the token is prefixed with Bot
. When a User token is supplied there is no Bot
prefix.
In discord.js the Bot
prefix is always supplied leading it to only work with bot tokens.
This is the most help I'll offer. If you can't do anything with this information then you are on your own.
Upvotes: 3