【问题标题】:Nextcord creating threads on commandNextcord 根据命令创建线程
【发布时间】:2022-12-26 04:32:09
【问题描述】:

是否可以使用 nextcord 按命令创建线程?我试着这样做,但没有成功。 PyCharm 没有给我任何错误信息。 这是我的代码:

@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)

错误在await nextcord.create_thread(name=f'{arg}', message=None, auto_archive_duration=60, type=None, reason=None),但我不知道哪里出了问题。

【问题讨论】:

  • 具体是什么错误?
  • 我没有收到任何错误。
  • 这可能与您使用的是 nextcord.create_thread 而不是 ctx.create_thread 有关。想想看。有了你现在的说法,discord怎么会知道在哪里你想创建线程?
  • 没有工作,我没有收到错误
  • 抱歉,ctx.channel.create_thread 应该可以解决问题。

标签: python discord nextcord


【解决方案1】:

您的问题是您没有指定在其中创建线程的频道。请尝试以下操作:

@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)

我在这里所做的是删除 nextcord,并将其替换为 ctx.channel。这样,您就指定了创建线程的通道。

在我看来,您不应该使用常规命令,如果您使用的是 Nextcode,则应该切换到 Slash 命令。在这种情况下,使用 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)

您应该能够将此代码复制并粘贴到您的 Python 文件中。希望所有这些都对您有所帮助!

【讨论】:

    猜你喜欢
    • 2022-08-10
    • 1970-01-01
    • 2022-10-04
    • 2022-11-10
    • 2022-08-10
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多