Python Forum
Python Bot Leave Server - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python Bot Leave Server (/thread-10148.html)



Python Bot Leave Server - Demotry - May-15-2018

I installed my bot in my friend's discord server. Now he kicked me from server so i need to block my bot to his server or i need to make my bot to leave his server.

I got a python scrpt in google search do i need to change this so it suits for me.

import discord

client = discord.Client()
my_server = client.get_server('server id')

@client.event
async def on_ready():
    for server in client.servers:
        if server != my_server:
            await client.leave_server(server)

@client.event
async def on_server_join(server):
    if server != my_server:
        await client.leave_server(server)
I need a script like example bot should leave server if I'm not in that server. If my bot is in 20 server and I'm member of only 10 server so it should leave other 10 server.


RE: Python Bot Leave Server - Demotry - May-15-2018

Is this possible to make my bot leave his server without his server ID. Or any code to make my bot leave all server except i mentioned servers list please...


RE: Python Bot Leave Server - micseydel - May-16-2018

I can't test this code and haven't looked at the docs, but I would imagine that you have some persistent identifier and that your bot can list the users. When it joins, it should check if you're there (hard-code your ID or put it in config somewhere), and then either listen for events where people leave or it should poll (occasionally check the people who are current there).