将频道提及转换为不和谐文本频道对象

Convert channel mention to discord text channel object

问题的措辞可能很奇怪,但我正在尝试让一个函数以频道提及和消息(字符串)作为参数;然后将消息发送到提到的频道。这个函数在 class (cog) 中,所以它有 self:

# Discord Imports
import discord
from discord.ext import commands
from discord.utils import get

class Author_Only(commands.Cog):
  def __init__(self,bot):
    self.bot=bot

  @commands.command(
  brief='Sends a message using Doge Bot')
  async def announce(self,ctx,channel,*,message:str): # I can't seem to find the proper conversion for a text channel, 
    await ctx.message.delete()                        # since you can do a similar thing with mentioning someone
    await channel.send(message)

您显然已经知道如何确保消息是一个字符串,而不是

str

discord.TextChannel

下面的例子

#Discord Imports
import discord
from discord.ext import commands
from discord.utils import get

class Author_Only(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
    
    @commands.command(brief="Sends a message using doge bot")
    async def announce(self, ctx, channel: discord.Channel, *, message: str):
        await ctx.message.delete()
        await channel.send(message)