Is it possible to create a thread on command with nextcord? I tried to do that , but it didn't work. PyCharm did not give me any error message. Here is my Code:
@bot.command(name='create_thread')
@commands.has_permissions(create_public_threads=True)
async def thread(ctx, *, arg):
await nextcord.create_thread(name=f'{arg}', message=None, auto_archive_duration=60, type=None, reason=None)
The error is in await nextcord.create_thread(name=f'{arg}', message=None, auto_archive_duration=60, type=None, reason=None)
, but I don't know what's wrong.
Your problem here is that you're not specifying the channel to create your thread in. Try the following:
@bot.command(name='create_thread')
@commands.has_permissions(create_public_threads=True)
async def thread(ctx, *, arg):
await ctx.channel.create_thread(name=f'{arg}', message=None, auto_archive_duration=60, type=None, reason=None)
What I did here is remove nextcord, and replace it with ctx.channel. This way, you're specifying the channel to create the thread in. Also the quotes are unnecessary. You can just remove the f'{}' and keep arg.
In my opinion, you shouldn't be using regular commands and should switch to Slash Commands if you're using Nextcord. In this scenario, here's what the command would look like using Slash Commands:
@bot.slash_command(name="thread", description="Create a thread in the channel this command is run in", guild_ids=[serverID])
@commands.has_permissions(create_public_threads=True)
async def thread(interaction: nextcord.Interaction, arg: str):
await interaction.channel.create_thread(name=f'{arg}', message=None, auto_archive_duration=60, type=None, reason=None)
You should just be able to copy and paste this code into your Python file. Hope all of this helped ツ