Skip to content

Instantly share code, notes, and snippets.

@funnbot
Last active December 5, 2022 10:55
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save funnbot/f6be8866ed468d80bfdc3463f7ba7564 to your computer and use it in GitHub Desktop.
Save funnbot/f6be8866ed468d80bfdc3463f7ba7564 to your computer and use it in GitHub Desktop.
if (process.version.startsWith("v6")) throw new Error("This Bot requires Node 7v+ because of async/await")
const Discord = require("discord.js")
const express = require("express")
const app = express()
const superagent = require("superagent")
//Config
let INVITE = process.env.INVITE || "", //An Infinite Invite to your discord server.
GUILD = process.env.GUILD || "", //The ID of the Guild for this invite ^
OWNER = process.env.OWNER || "", //Your main account id so the bot can notify if it finds an advertiser
TOKEN = process.env.TOKEN || "", //The user token for your alt,
ONLYADVERT = process.env.ONLYADVERT || false, //If the bot should notify on every dm or only if it contains an invite link
APPID = process.env.APPID || "", //APp ID BRO, THis must be of a bot in the guild that you are monitoring
APPSECRET = process.env.APPSECRET || "",
APPSCOPE = process.env.APPSCOPE || "guilds.join",
APPREDIRECT = process.env.APPREDIRECT || ""
//End Config
const client = new Discord.Client({
messageCacheMaxSize: 1, //Minimize RAM Load
disabledEvents: ["TYPING_START"] // ^^
})
let loop24H = () => { //The bot will leave then join the guild every 24 hours
leaveJoin()
let evade = Math.floor(Math.random() * 100000) - 50000
let time = 86400000 + evade
setTimeout(() => loop24H(), time)
}
let wait10 = () => new Promise(resolve => setTimeout(resolve, 10000))
//Begin The Beef
let cachedDMS = []
let sinceLastLJ = 0
//Ready Event
client.on("ready", () => {
console.log("Started")
if (client.user.bot) throw new Error("Auto DM Advert Checker only works on User Acounts.")
})
let ranOnce = false
let appReady = () => {
if (ranOnce) return
console.log("App Is Ready")
loop24H()
}
//Message Event
client.on("message", async message => {
if (message.author.id === client.user.id) return
if (message.channel.type !== "dm") return
if (ONLYADVERT && !/discord\.gg\/\w+|bot\.discord\.io\/\w+|discordapp\.com\/invites\/\w+|discord\.me\/\w+/g.test(message.content)) return
let owner = client.users.get(OWNER)
let over = Date.now() - sinceLastLJ < 60000 ? "Less than a minute after I joined." : "Out of the blue."
if (!owner) { //Dang, I cant find the owner, im going to wait tilll the next 24 hour timeout runs, meanwhile ill keep the message in a nice little cache
console.log("I could not find the owner, caching till next leaveJoin.")
let msg = {
content: message.content,
author: {
id: message.author.id,
tag: message.author.tag
},
over
}
return cachedDMS.push(msg)
}
let txt = `Direct message from: **${message.author.tag} (${message.author.id})**\n**Context:** ${over}\n\n**Content:** ${message.content}`
try {
await owner.send(txt)
} catch (err) {
console.log("I can't DM the OWNER.")
}
})
//Leave then Join server
let leaveJoin = async() => {
sinceLastLJ = Date.now()
let guild = client.guilds.get(GUILD)
if (!guild) {
console.log("I'm not in the guild already, re-running.")
try {
await acceptInvite()
return //leaveJoin()
} catch (err) {
throw new Error("Invalid INVITE")
}
}
if (guild.ownerID !== OWNER) throw new Error("Please only run this bot if you are the owner of the server.")
try {
await guild.leave()
console.log("Leaving")
await wait10()
console.log("Waited 10 Seconds")
await acceptInvite()
console.log("Re-Joined")
} catch (err) {
return console.log(err)
}
let owner = client.users.get(OWNER)
if (!owner) throw new Error("I joined the guild but I cannot find the you.")
if (cachedDMS.length > 0) {
let txt = cachedDMS.map(m => `**${m.author.tag} (${m.author.id})**\n**Context:** ${m.over}\n\n**Content:** ${m.content}`)
try {
await owner.send("**Sending Cached DM's**")
await owner.send(txt)
} catch (err) {
console.log("I can't DM the OWNER.")
}
}
}
//Login
client.login(TOKEN)
//THe WebServer because Discord Is Mean
const APP = {
ID: APPID, //This is the ID of your Application
SECRET: APPSECRET, //This is the Secret of your application
SCOPE: APPSCOPE,
REDIRECT: APPREDIRECT
}
let access_token = null
let refresh_token = null
let acceptInvite = () => {
console.log("trying")
return new Promise((resolve, reject) => {
if (!access_token) return console.log("Accept Auth URI First to join the guild.")
let JOIN_URI = `https://discordapp.com/api/invites/${INVITE}`
superagent.post(JOIN_URI).set({
Authorization: `Bearer ${access_token}`
}).then((response) => {
resolve()
}).catch(console.log)
})
}
const AUTH_QUERY = [
`client_id=${APP.ID}`,
`scope=${APP.SCOPE}`,
`redirect_uri=${APP.REDIRECT}`,
'response_type=code',
].join('&');
const AUTH_URL = `https://discordapp.com/oauth2/authorize?${AUTH_QUERY}`;
console.log(AUTH_URL)
app.use("/callback", (req, res) => {
if (req.query.error) return console.log(req.query.error)
if (!req.query.code) console.log("Req.Code Errored Bad!")
let code = req.query.code
res.send("Success!")
const TOKEN_PARAMS = [
'grant_type=authorization_code',
`code=${code}`,
`client_id=${APP.ID}`,
`client_secret=${APP.SECRET}`,
`redirect_uri=${APP.REDIRECT}`,
].join('&');
const TOKEN_URI = `https://discordapp.com/api/oauth2/token?${TOKEN_PARAMS}`
superagent.post(TOKEN_URI).then(response => {
if (!response.body.access_token) throw new Error("Didnt get a token from TOKEN_URI")
access_token = response.body.access_token
refresh_token = response.body.refresh_token
console.log("Refresh: " + refresh_token)
appReady()
})
})
app.listen(2001, () => console.log("Listening On 2001"))
@funnbot
Copy link
Author

funnbot commented Aug 1, 2017

BRAINS

@maimark5
Copy link

Does this really work? I friend of mine is running a bot that is build for the same purpose and he won't teach me anything...

@tuia2005
Copy link

how can i do that teach me pls

@tuia2005
Copy link

dm me on discord : arthur {Buying}{selling}#6935

@blubaustin
Copy link

Installation instructions would be nice. Thing I'm stuck on is the oauth.

@0xFaisal
Copy link

anyone need help, i can do it,
https://discord.gg/uYbSm8B
and talk me!

@JoanOlucha
Copy link

anyone need help, i can do it,
https://discord.gg/uYbSm8B
and talk me!

Link expired

@Barri2k18
Copy link

Selfbots & mass dm advert bots are against Discord's ToS so don't do this

@denseje
Copy link

denseje commented Apr 9, 2019

i dont understand anything add me freedecx#5540 or join this server and then dm me https://discord.gg/PB5Wsv

@Vrgn123
Copy link

Vrgn123 commented May 13, 2019

Can anyone help me set this up? add Beeza YT#8806

@NiklavsD
Copy link

Could I get some help? Almost done setting up, but not working!
Niklavs#5878
Please!

@NiklavsD
Copy link

NiklavsD commented Sep 1, 2019

I figured it out!
If anyone need help - https://discordapp.com/invite/xFCAKUn
P.S - This is not auto DM spam bot! It’s intended to do exactly the opposite - prevent DM spamming in your server by detecting those, who do!
Auto DM advertisement check.js

@Sfuniversal
Copy link

Bruh this is against terms but If its for educational purposes you can join my server and Ill tell you https://discord.gg/web3A73

@NothingHollow
Copy link

Hmm it breaks ToS, so it's bad but if it's For an [Educational Purposes] when we all knew you're gonna use it but plz don't because dm ads really annoyin right.
Okay so if you wanted to do Discord.JS this dm ads code FOR EDUCATIONAL PURPOSE because i hate dm advertising myself
I'd probs help you or u want another code, go to this server i attached the link join it here

@BrokenKaneki
Copy link

what modules to use?

@funnbot
Copy link
Author

funnbot commented Sep 7, 2021

This was made to automatically find out if an ad bot had joined a server and alert the owner. Selfbots break TOS. but at the time discord did not care about the amount of ad bots, so I really don't care that it did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment