在discord.py中,我如何做到这一点,因此该漫游器只能在一台服务器上工作 [英] in discord.py how do i make it so the bot only works in one server

查看:68
本文介绍了在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天全站免登陆