I have a discord.js self-bot, and I'm trying to make it create a server, any help would be great.
I've tried messing around with client.user but I didn't find anything
Also if you cant create a server using discord.js (because its not meant for selfbots) im willing to use a external library (request, axios etc..)
I'm using discord.js-selfbot (discord.js v12)
client.on('message', message => {
if (message.content === '!createserver') {
// make server here
message.reply('Created server!')
}
})
While I don't condone self botting due to terms, but the answer is very easily findable on the documentation for discord.js, right here assuming it exactly copies v12.
The documentation for the endpoint is available here if the copied package does not work. Or just install a working version of it using the actual discord.js package, like npm i discord.js#12.5.3.
Just be careful with self botting, for obvious reasons.
Related
I am yet to code this but actually struggling to understand how to do this
There is a private server with paid membership. I am a member. There are many channels on that server. I am particularly interested in a specific channel. Once someone posts a message in that channel, I want to immediately extract that message from a different program automatically and then process it in downstream systems. How to do that?
I know I'm a bit late to this question, but I'm going to tell you the secrets the Discord elites don't want you to know: This is completely doable, and many people do it. It's called a "self-bot".
Disclaimer: As the other answer stated, this is against ToS. You probably won't be caught, but I'd keep this on the down-low. Definitely don't go around telling this to everyone you meet.
Ok, now here's the actual coding part:
Discord.js, the most common library for discord bots in JavaScript, no longer supports self-bots, so you'll need to use an older version of discord.js. The official old versions have some unresolved bugs when used with modern discord, so I like to go with discord.js.v11.patch. Using this patched package will fix any weird bugs you get. Note: this is still discord.js v11, so if you need documentation, be sure to look at the v11 docs.
Ok, so after you run npm install discord.js.v11.patch (or npm install -g discord.js.v11.patch if you want to install it globally), you'll need to start writing code. Everything is basically the same as any old discord.js bot, but this is v11 so some stuff might be different. Here's some code to get you started. It should do everything you want it to do:
const discord = require('discord.js.v11.patch');
const client = new discord.Client();
const USER_TOKEN = 'XXXXXXXXXXXXXX'; // change this to your token
const CHANNEL_ID = 'XXXXXXXXXXXXXX'; // change this to the chanel you want to listen to.
client.on('ready', () => {
console.log('bot is running');
});
client.on('message', msg => {
if (msg.channel.id != CHANNEL_ID) return;
const message_text = msg.content;
console.log(message_text); // just an example
// send message_text somewhere to process it.
});
client.login(USER_TOKEN);
Now, all you need to do is change USER_TOKEN to your discord token and CHANNEL_ID to the ID of the channel you want to listen to.
To get your token, I recommend using this gist. It is safe and minimal. If you are worried about accessing your token, don't be. As long as you don't give it to anyone else you're fine.
To get the channel ID, simply turn on developer mode, then right-click on the channel you want to listen to. You should see a Copy ID menu button at the bottom of the context menu.
You can only do this if you have permissions to add an actual bot to that server, or have a friend that can do this for you. Using your own account as a bot would be possible, but is against discord ToS and would get your account banned.
I have tried using the client.on('guildDelete', () => {remove roles and other things}) , but everytime the bot is removed from my test server it says "Missing Access" (even though my bot has adminstrative privelages on my test server, and all other features work). I am assuming this is because the event is registered after the bot is removed from the server, which would make sense and is why I am tring to find away around that. Any and all help is appreciated.
Full source code: https://github.com/blb7103/sw-bot
Precisely what you said -- the event fires when the bot has officially left the server, and therefore cannot access/edit anything within that server.
There are no workarounds to this.
I am trying to make some "commands" work only for a specific server, so when used in a different server it would say something like This command can only be used in [GUILD] server.
Let me know if anyone has any solutions. Thanks!
Before executing your command's function, you can check this :
if (message.guild.id !== 'TheIdOfYourGuild') return message.reply('This command can only be used in another server.');
I have been working on a discord bot and I want to send a message as soon as it gets online in a set announcement channel. I think I know how to make it work but I keep getting the same problem. I've read several articles but they don't solve the problem I have client.channels.get is not a function.
I don't just want to change it to a channel Id as I want it to be possible to be used on other servers than mine. I am a newbie in discord API and coding in general. That is why I don't use too advanced coding as I want to learn what it does instead of copying something I don't understand.
Thanks.
In order to get any properties from the client object, it needs to be loaded from within an event. Say for example inside the ready event, i.e. when the bot is fully loaded, you can then do client.channels.cache.find(channel => channel.name == "name_of_channel"), etc. To listen to an event, you do client.on("event_name_here", (parameters) => {}).
To view a list of events, take a look at: https://discord.js.org/#/docs/main/stable/class/Client
If this didn't help, please post your code so we can properly determine the issue.
Since discord.js v12 you now need to use .cache to access channels collection.
Use client.channels.cache.get() or client.channels.cache.find(channel => channel.name === 'Test') instead.
I am trying to make a discord bot. However, i am stuck on a part where i have to check every hour if a discord username is equal to the contents of an array. If it is, I have to make the bot remove a role. However, doing so would require using the discord.js module, which I don't know how to add into the code (I already have the bot set up in index.js).
I've tried to require discord.js-commando but it returns:
"Error: A client must be specified"
This is the place of the problem:
class checkDet extends commando.Command {
This is where I want to use the discord.js module:
var guild = bot.guilds.get("GUILD ID HERE");
for (let [k, v] in Object.entries(guild.members)) {
if (v.user.username == userName)
{
v.removeRoles(v.roles).then(console.log).catch(console.error);
}
}
Multiple solutions. Solution 1: if you're just using Discord.JS and not the whole Commando module, try using const Discord = require('discord.js'); at the top of that file and use
it as normal!
Another method would be to pass the whole commando module through. There's many ways to do it, however the easiest is probably to add let commando; at the top of the file, then create a module.exports.define function to set commando to the first argument. Then in the main bot file, run require('path/to/my/command.js').define(commando);.
Or even simpler, if all you need is a recursive check, why not put it in the main bot.js file, or even another file? Either invoke the file including the commando object, or just run a setInterval in the original file with the normal code.