简体   繁体   English

我如何让我的 Python 3.6.1 Discord 机器人在服务器中创建一个新的文本通道?

[英]How would I make my Python 3.6.1 Discord bot create a new text channel in a server?

I have been reading the documentation.我一直在阅读文档。 The documentation shows this example:文档显示了这个例子:

channel = await guild.create_text_channel('cool-channel')

I need to figure out what to do with guild so that there is no NameError regarding guild .我需要弄清楚如何处理guild以便没有关于guild NameError (Do I have to import guild ? etc.) (我必须导入guild吗?等)

Documentations:文件:

If you are using the rewrite branch, to create a text channel you would need to do 如果您使用重写分支,则需要创建一个文本通道

guild = ctx.message.guild
await guild.create_text_channel('cool-channel')

If you are using the unsupported async branch, to create a text channel you would need to do 如果您使用的是不受支持的异步分支,则需要创建一个文本通道

server = ctx.message.server
await client.create_channel(server, 'cool-channel', type=discord.ChannelType.text)

If you need to figure out which branch you are using, you can do print(discord.__version__) . 如果需要弄清楚正在使用哪个分支,可以执行print(discord.__version__) If the version is 0.16.2 or lower, then it is async. 如果版本为0.16.2或更低,则为异步。 If it is 1.0.0a, then it is the rewrite 如果是1.0.0a,则为重写

I made my command like this, don't know if you can use it, but it works fine for me so:我的命令是这样的,不知道你是否可以使用它,但它对我来说很好用,所以:

@client.command()
async def create(ctx, *, name=None):
  guild = ctx.message.guild
  if name == None:
    await ctx.send('Sorry, but you have to insert a name. Try again, but do it like this: `>create [channel name]`')
  else:
    await guild.create_text_channel(name)
    await ctx.send(f"Created a channel named {name}")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的 discord 机器人使用 Hikari 的命令在不同的频道中说出一条消息 - How would I make my discord bot say a message in a DIFERENT channel with a command using Hikari 如何使用 discord.py 和 Python 3.6.1 创建频道? - How to create a channel using discord.py and Python 3.6.1? 如何让我的 discord 机器人获取所有服务器中的所有文本通道 ID? - How do I make my discord bot get all text channel id's in all servers? 如何使用 discord 机器人创建新频道? - How to create new channel with discord bot? 如何让我的 discord 机器人加入*类别*中的语音频道? - How to I make a my discord bot join a voice channel *in a category*? 在 Python 中编程 Discord 机器人 - 我将如何制作它以便我的静音命令是定时的? - Programming a Discord bot in Python- How would I make it so my mute command is timed? 我将如何在 Python 中为 discord bot 执行重新加载命令? - How would I make a reload command in Python for a discord bot? 我将如何将 GIPHY Python API 与我的不和谐机器人一起使用? - How would I use the GIPHY Python API with my discord bot? 我如何使用 python 在我的 discord 机器人上添加冷却时间 - How would i add cooldown on my discord bot using python python discord bot create_channel commmand向命令添加arg以使bot将服务器的特定成员添加到通道的权限 - python discord bot create_channel commmand adding an arg to command to make bot add a specific member of the server to the perms of the channel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM