发送用户指定的消息到指定的通道

  • 本文关键字:通道 消息 用户 discord.py
  • 更新时间 :
  • 英文 :


这个机器人只供个人使用,所以我不需要从discord本身定制它。我想知道我是否可以把ctx.sendchannel.send放在一起,如果这有意义的话。下面是我的代码,以帮助您理解我的意思:

client = commands.Bot(command_prefix='!')
channel = client.get_channel(883389016819511296)
@client.command(name='say')
async def say(ctx, *, content):
await ctx.send(content) # here I want to send it to the channel I already defined

channel.send将是一个选项,但我也想发送消息,所以如果我是正确的,我需要使用ctx

不,您需要使用channel。在将内容发送到指定通道时发送。如果你使用ctx。它将在执行命令的同一通道中发送。如果你想看的话,有一个更简单的方法我这里有一个例子

@client.command() async def say(ctx, channel: discord.TextChannel, *, message: str): await channel.send(message)

这是一个更简单的方法,你可以"#"文本通道,例如,如果你想为你的机器人发送一条消息,它将是:但是,如果你只是想这样做,而不是使用我的例子,那么你应该这样做:

@client.command(name='say') async def say(ctx, *, content): channel = client.get_channel(883389016819511296) await channel.send(content)

最新更新