我正在编写Discord Bot,我想知道如何从任何用户的消息中获取频道ID。
我实际上想制作一个文本机器命令。当用户处于AFK或离线状态时,它会给用户留下一条消息。当他们回来并在服务器中的任何通道中发送消息时,机器人会立即将消息发送到同一通道。
@client.command()
async def txt(ctx, receiver: discord.Member, *, message):
await ctx.message.delete()
def check(message: discord.Message):
return message.author == receiver
newembed = discord.Embed (title='On-Message Scheduled', description=f'Message will be delivered to the receiver as soon as he messages. n Message: `{message}` n to **{receiver}**')
channel = await ctx.message.author.create_dm()
x = await channel.send(embed=newembed)
msg = await client.wait_for('message', check = check)
await ctx.send(f'TEXT MACHINE n **{ctx.message.author}:** `{message}`n for {receiver.mention}')
await x.add_reaction('✅')
这在一定程度上确实有效。但问题是,如果我这样做,比如说>txt @User#1234 this is a message
命令在通道1上,用户消息在通道2上,机器人会将消息发送到通道1,但我希望机器人将消息发送给用户消息的通道。
我们将不胜感激,谢谢。
这很简单,只是不使用ctx.send,而是使用msg.channel.send。所以从末尾开始的第二行看起来是这样的:
await msg.channel.send(f'TEXT MACHINE n **{ctx.message.author}:** `{message}`n for {receiver.mention}')