[英]How would I make my Python 3.6.1 Discord bot create a new text channel in a server?
I have been reading the documentation.我一直在阅读文档。 The documentation shows this example:
文档显示了这个例子:
channel = await guild.create_text_channel('cool-channel')
I need to figure out what to do with guild
so that there is no NameError
regarding guild
.我需要弄清楚如何处理
guild
以便没有关于guild
NameError
。 (Do I have to import guild
? etc.) (我必须导入
guild
吗?等)
Documentations:文件:
If you are using the rewrite branch, to create a text channel you would need to do 如果您使用重写分支,则需要创建一个文本通道
guild = ctx.message.guild
await guild.create_text_channel('cool-channel')
If you are using the unsupported async branch, to create a text channel you would need to do 如果您使用的是不受支持的异步分支,则需要创建一个文本通道
server = ctx.message.server
await client.create_channel(server, 'cool-channel', type=discord.ChannelType.text)
If you need to figure out which branch you are using, you can do print(discord.__version__)
. 如果需要弄清楚正在使用哪个分支,可以执行
print(discord.__version__)
。 If the version is 0.16.2 or lower, then it is async. 如果版本为0.16.2或更低,则为异步。 If it is 1.0.0a, then it is the rewrite
如果是1.0.0a,则为重写
I made my command like this, don't know if you can use it, but it works fine for me so:我的命令是这样的,不知道你是否可以使用它,但它对我来说很好用,所以:
@client.command()
async def create(ctx, *, name=None):
guild = ctx.message.guild
if name == None:
await ctx.send('Sorry, but you have to insert a name. Try again, but do it like this: `>create [channel name]`')
else:
await guild.create_text_channel(name)
await ctx.send(f"Created a channel named {name}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.