in discord.py how do i make it so the bot only works in one server

后端 未结 1 1986
暖寄归人
暖寄归人 2021-01-29 11:19

in discord.py, how do I make it so the bot only works on one? so is there a way do this

x = (channel id.)

if x == (12454431344645423) #this is the channel id 
         


        
相关标签:
1条回答
  • 2021-01-29 11:34

    The easiest way is to just not add it to any other servers. You can also just leave all the servers but one in your on_ready event, and then leave other servers as you join them.

    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)
    
    0 讨论(0)
提交回复
热议问题