Python 将频道提及转换为不协调文本频道对象
这个问题的措词可能有点奇怪,但我正试图让一个函数以频道名称和消息(字符串)作为参数;然后将消息发送到上述频道。此函数位于类(cog)中,因此它具有Python 将频道提及转换为不协调文本频道对象,python,discord.py-rewrite,Python,Discord.py Rewrite,这个问题的措词可能有点奇怪,但我正试图让一个函数以频道名称和消息(字符串)作为参数;然后将消息发送到上述频道。此函数位于类(cog)中,因此它具有self: #不一致导入 进口不和 从discord.ext导入命令 从discord.utils导入获取 仅类作者(commands.Cog): def uuu init uuuu(自我,机器人): self.bot=bot @命令( brief='使用Doge Bot'发送消息〕 async def annound(self、ctx、channel
self
:
#不一致导入
进口不和
从discord.ext导入命令
从discord.utils导入获取
仅类作者(commands.Cog):
def uuu init uuuu(自我,机器人):
self.bot=bot
@命令(
brief='使用Doge Bot'发送消息〕
async def annound(self、ctx、channel、*,message:str):#我似乎找不到文本频道的正确转换,
等待ctx.message.delete()
等待通道。发送(消息)
您显然已经知道如何确保消息是一个字符串,对于一个频道而不是
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)
我想我忘了回来回答这个问题,因为很久以前我已经从discord.py discord服务器找到了解决方案;但是谢谢你回答一个老问题。是的,没问题