我正在使用discord.py制作一个bot,我正在尝试获取频道名称以确认在何处发送嵌入内容,例如:
您希望将嵌入发送到哪里?
1-#概述
2-不同频道
以下是我尝试使用的代码:
channel = client.get_channel(ctx.author)
我得到这个错误
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'context' object has no attribute 'text_channel'
谢谢!
2条答案
按热度按时间mjqavswn1#
简单看一下文档就会知道,您可以通过执行以下操作从context对象获取channel对象
你可以这样做:
您将注意到,您还可以在命令调用中传递一个channel对象,就像我上面演示的那样。
6tqwzwtp2#
clint.get_chanel
可以按通道的id使用。如果要获取名为的频道,请使用
discord.utils
```channels = [c for g in client.guilds for c in g.text_channels] #getting all the text channels bot can see
channel = discord.utils.get(channels, name="general")