如何使用Discord bot创建新频道?

时间:2020-05-20 11:21:37

标签: python discord channel

我需要在python中创建新频道。文档建议:

await guild.create_text_channel('cool-channel')

但是它不起作用,所以我尝试了这个:

await client.get_guild(guild.id).create_text_channel('test')

但这会引发另一个错误:

AttributeError: 'NoneType' object has no attribute 'create_text_channel'

1 个答案:

答案 0 :(得分:0)

在没有看到其余代码的情况下,我无法真正说出具体错误的地方,但我将提供一些示例:

@client.command()
async def makechannel(ctx, *, name):
    channel = await ctx.guild.create_text_channel(name.replace(" ", "-"))
    await ctx.send(f"Successfully created {channel.mention}!")

##############################################################

@client.command()
async def makechannel(ctx, *, name):
    guild = client.get_guild(SOME_GUILD_ID) # you could add the guild id as an arg if you want
                                            # make sure it's an int
    channel = await guild.create_text_channel(name.replace(" ", "-"))
    await ctx.send(f"Successfully created a text channel in **{guild.name}**!")

参考:

相关问题