我正在使用 discord.py 制作一个机器人,我正在尝试获取频道名称以确认将嵌入内容发送到何处,例如:
您希望将嵌入的内容发送到哪里?
1 - #general
2 - 不同的渠道
这是我尝试使用的代码:
channel = client.get_channel(ctx.author)
我收到此错误
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'context' object has no attribute 'text_channel'
谢谢!
答案 0 :(得分:0)
作为 brief glance at the docs would have told you,您可以通过执行以下操作从上下文对象中获取通道对象
app.get('/home', (req, res, auth) => {
... do code ...
})
你可以像这样做一些不同的事情:
channel = ctx.channel
您会注意到,您还可以像我上面演示的那样在命令调用中传递一个通道对象。
答案 1 :(得分:0)
clint.get_chanel
可以通过频道的 id 使用。
channel = client.get_channel(123456789123456789)
await channel.send("message")
如果您想获取带有名称的频道,请使用 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")
另外,如果你有公会,你可以用channels
或guild.text_channels
等替换guild.voice_channels