在 discord.py 中,我怎么做才能让机器人只在一台服务器上工作 [英] in discord.py how do i make it so the bot only works in one server

查看:24
本文介绍了在 discord.py 中,我怎么做才能让机器人只在一台服务器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 discord.py 中,我怎样才能让机器人只在其中一个上工作?那么有没有办法做到这一点

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 
       print ('hi')

推荐答案

最简单的方法是不将其添加到任何其他服务器.您也可以在 on_ready 事件中只保留除一个以外的所有服务器,然后在加入时离开其他服务器.

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)

这篇关于在 discord.py 中,我怎么做才能让机器人只在一台服务器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆