问题的措词可能很奇怪,但是我试图让一个函数将频道提及和消息(字符串)作为参数。然后将消息发送到提到的频道。此函数在类(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)
答案 0 :(得分:1)
您显然已经知道如何确保消息是字符串,而对于频道而言,恰恰是
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)