Python 如何获得频道名称Discord.py重写

Python 如何获得频道名称Discord.py重写,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,我正在使用discord.py制作一个bot,我正在尝试获取频道名称,以确认在何处发送嵌入,如: 您希望将嵌入发送到哪里 1-#概述 2-不同频道 以下是我尝试使用的代码: channel = client.get_channel(ctx.author) 我得到这个错误 discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'context' object has

我正在使用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'
谢谢

作为一个示例,您可以通过执行以下操作从上下文对象获取通道对象

channel=ctx.channel
你可以做一些不同的事情,像这样:

@bot.command()
异步定义使嵌入(ctx,嵌入内容,频道:discord.channel):
#在此处创建您的嵌入
wait ctx.send(f“您的意思是将嵌入发送到{ctx.channel.name}还是{channel.name}?”)

您会注意到,您还可以在命令调用中传递通道对象,如我上面演示的那样。

clint.get\u 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")
此外,如果你有帮会,你可以用
guild.text\u频道
guild.voice\u频道
e.t.c.替换
channels