Bcat13
Bcat13

Reputation: 37

Discord Self-Bot: Direct messaging a user when joining a server/guild

I am trying to create a bot to run through my personal discord account, and direct message people when they join a specific discord server I am in. However, my on_member_join(member) method is not running when a member joins a server (not printing "registered" in terminal). I am curious how to make the bot listen for a specific server or just register this event in general. Note on_connect() and spam() both function properly.

import discord
import asyncio
import requests
from discord.ext import commands
yer=commands.Bot(command_prefix="!",help_command=None,self_bot=True)
token="TOKEN"

class SelfBot(commands.Cog):
    def __init__(self,yer):
        self.yer=yer

   @yer.command()
   async def spam(ctx):
        for i in range(50):
            await ctx.send("Hello!")
            await asyncio.sleep(0.7)

    @yer.event
    async def on_connect():
        await yer.change_presence(status=discord.Status.idle,activity=discord.Game("Game"))

   @yer.event
   async def on_member_join(member):
       print("registered")

yer.run(token,bot=False)

Upvotes: 2

Views: 12668

Answers (1)

vgalin
vgalin

Reputation: 526

Self bots are not authorized on Discord and can get your account banned.

Discord's API provides a separate type of user account dedicated to automation, called a bot account. Bot accounts can be created through the applications page, and are authenticated using a token (rather than a username and password). Unlike the normal OAuth2 flow, bot accounts have full access to all API routes without using bearer tokens, and can connect to the Real Time Gateway. Automating normal user accounts (generally called "self-bots") outside of the OAuth2/bot API is forbidden, and can result in an account termination if found.

You won't be able to do those kind of things with the official discord.py module and I'm not sure that you will be able to receive help on StackOverflow if you choose something else to build a self-bot.

Upvotes: 3

Related Questions