Skip to content Skip to sidebar Skip to footer

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

Solution 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

Solution 2:

I made my command like this, don't know if you can use it, but it works fine for me so:

@client.command()asyncdefcreate(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}")

Post a Comment for "How Would I Make My Python 3.6.1 Discord Bot Create A New Text Channel In A Server?"