简体   繁体   中英

Replace whitespaces with “-” for a channel name discord.py

Im using a basic command to create a channel. The issue is that when I provide a channel name with whitespaces for example: hello its me, the bot creates a channel named hello. How can I fix this? Here's the command I have tried:

@bot.command()
async def create(ctx, name):
 guild = ctx.message.guild
 newname=name.replace(" ", "-")
 await guild.create_text_channel(newname)

This is probably just an issue with how you are calling the command. discord.py separates positional arguments by space, so if you type the command !create hello its me , the create command is called and hello is passed as the name argument. To negate this feature of separating positional arguments, just wrap the text you're passing with single or double quotes.

So, instead of:

!create hello its me

you would call the command with:

!create "hello its me"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM