Python 如何在_ready discord.py上创建频道?
当bot启动时,我正试图创建come频道。我想让它们在函数中创建。但是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
等待公会。创建文本频道(“频道”)
需要公会自己。通常,当我想通过命令创建它时,我会这样做:
@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”)
参考: