问题
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
. (Do I have to import guild
? etc.)
Documentations:
http://discordpy.readthedocs.io/en/rewrite/api.html#discord.Guild.create_text_channel
http://discordpy.readthedocs.io/en/rewrite/api.html#guild
回答1:
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__)
. If the version is 0.16.2 or lower, then it is async. If it is 1.0.0a, then it is the rewrite
来源:https://stackoverflow.com/questions/48141407/how-would-i-make-my-python-3-6-1-discord-bot-create-a-new-text-channel-in-a-serv