如何让我的 Python 3.6.1 Discord 机器人在服务器中创建新的文本通道?

2024-01-26

我一直在阅读文档。文档显示了这个示例:

channel = await guild.create_text_channel('cool-channel')

我需要弄清楚该怎么办guild这样就没有NameError关于guild。 (我必须导入guild? etc.)

文档:

  • http://discordpy.readthedocs.io/en/rewrite/api.html#discord.Guild.create_text_channel http://discordpy.readthedocs.io/en/rewrite/api.html#discord.Guild.create_text_channel

  • http://discordpy.readthedocs.io/en/rewrite/api.html#guild http://discordpy.readthedocs.io/en/rewrite/api.html#guild


如果您使用重写分支,要创建文本通道,您需要执行以下操作

guild = ctx.message.guild
await guild.create_text_channel('cool-channel')

如果您使用的是不受支持的异步分支,要创建文本通道,您需要执行以下操作

server = ctx.message.server
await client.create_channel(server, 'cool-channel', type=discord.ChannelType.text)

如果您需要弄清楚您正在使用哪个分支,您可以这样做print(discord.__version__)。如果版本是 0.16.2 或更低,那么它是异步的。如果是1.0.0a,那么就是重写

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让我的 Python 3.6.1 Discord 机器人在服务器中创建新的文本通道? 的相关文章

随机推荐