我需要用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'
在没有看到你其他代码的情况下,我也不好说具体哪里出了问题,但我还是提供几个例子。
@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}**!")
引用
Guild.create_text_channel()
Client.get_guild()
- 这将返回 None
如果没有找到该ID的公会