Skip to content Skip to sidebar Skip to footer

Im Learning To Make A Bot Using Python. What Do I Do So That I Can Create A New Channel Using The Commands?

Thanks for the previous people that helped me for the last question What Im trying to do is make a different file for a function which is when you type '!Create' + (The name I want

Solution 1:

From the comments, I assume you want to create a channel via a command. To accomplish this you need to consider a few things:

If you want to use commands you have to change client = discord.Client() to client = commands.Bot(command_prefix="YourPrefix") and import commands from discord.ext:

from discord.ext import commands

client = commands.Bot(command_prefix="!") # Example prefix

First: You have to set up conditions, which have to be fulfilled. You want to be able to give the channel its own name? Assume this as the required argument:

@client.command()asyncdefcchannel(ctx, *, name):
  • We said that name is a required argument.
  • * is used so that we can also inpute names like t e s t and not only test.

Second: You need to define the guild where you want to create the channel. To do that we use:

guild = ctx.message.guild

Finally we want to create a text channel. To do this we use:

@client.command()asyncdefchannel(ctx, *, name):
    guild = ctx.message.guild # Get the guildawait guild.create_text_channel(name=name) # Create a text channel based on the inputawait ctx.send(f"Created a new channel with the name `{name}`") # Optional
  • While creating the channel we said that the name should be our required argument name.

Post a Comment for "Im Learning To Make A Bot Using Python. What Do I Do So That I Can Create A New Channel Using The Commands?"