如何用discord机器人创建新频道?

问题描述 投票:0回答:1

我需要用python创建一个新的频道。文档中建议使用.NET来创建新的频道。

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'
python discord channel
1个回答
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}**!")

引用

© www.soinside.com 2019 - 2024. All rights reserved.