How would I make my Python 3.6.1 Discord bot create a new text channel in a server?

陌路散爱 提交于 2019-12-11 06:26:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!