【问题标题】:How can I create text channels using discord.py?如何使用 discord.py 创建文本频道?
【发布时间】:2020-11-19 17:07:04
【问题描述】:
我正在尝试创建一个创建文本通道的命令。但是,它不起作用。它甚至没有显示错误。我正在使用 Discord.py 重写。
这是我尝试过的代码:
@client.command()
async def addcha(ctx, channel : discord.TextChannel):
await ctx.guild.create_text_channel(channel=None)
await ctx.send(f"A new channel called {channel} was made")
【问题讨论】:
标签:
discord
discord.py
discord.py-rewrite
【解决方案1】:
等待 ctx.guild.create_text_channel(channel=None)
Guild.create_text_channel 没有channel kwarg,所以不确定你想在这里做什么。此外,我认为您不能使用converter 将您的论点转换为尚不存在的TextChannel。您只需传入频道名称即可。
@client.command()
async def addcha(ctx, channel_name):
await ctx.guild.create_text_channel(channel_name)
await ctx.send(f"A new channel called {channel_name} was made")
有关在相关API Docs 中创建TextChannel 时可以执行的操作的更多信息。