Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在_ready discord.py上创建频道?_Python_Discord_Discord.py - Fatal编程技术网

Python 如何在_ready discord.py上创建频道?

Python 如何在_ready discord.py上创建频道?,python,discord,discord.py,Python,Discord,Discord.py,当bot启动时,我正试图创建come频道。我想让它们在函数中创建。但是等待公会。创建文本频道(“频道”)需要公会自己。通常,当我想通过命令创建它时,我会这样做: @client.command() async def create(ctx): guild = ctx.guild await guild.create_text_channel(name="test channel")``` But I need ctx to create guild. So

当bot启动时,我正试图创建come频道。我想让它们在函数中创建。但是
等待公会。创建文本频道(“频道”)
需要公会自己。通常,当我想通过命令创建它时,我会这样做:

@client.command()
async def create(ctx):
    guild = ctx.guild
    await guild.create_text_channel(name="test channel")```

But I need ctx to create guild. So the question is: How do I create a channel without ctx? 

你只需要获得一个
discord.Guild
实例,你可以使用
Bot.get\u Guild

async def on_ready():
等待客户端。等待,直到准备就绪()
帮会=客户。获取帮会(此处为id)
等待公会。创建文本频道(name=“whatever”)
如果你想在机器人所在的所有公会中创建一个频道,你可以通过
client.guilds

async def on_ready():
等待客户端。等待,直到准备就绪()
对于client.guilds中的帮会:
等待公会。创建文本频道(name=“whatever”)
参考: