python-3.x - 如何获取用户消息的频道 ID?
问题描述
我正在编写一个 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。所以从 end 开始的第二行将如下所示:
await msg.channel.send(f'TEXT MACHINE \n **{ctx.message.author}:** `{message}`\n for {receiver.mention}')
推荐阅读
- r - 当数字超过 9 个时在 R 中排序
- linux - 当 memset_io'ing 在 Petalinux 内核模块的设备树内存区域上时出现 SError 内核恐慌
- python-3.x - 我无法使用各种选项在 Twitter API v2 上进行搜索
- python-3.x - 如何使用 pandas python 对特定列进行操作第 3 部分
- c# - 从 azure blob 存储下载 zip 后无法访问 zip
- c# - MonoDevelop C# 上的“错误 MSB4186:无效的静态方法调用语法”
- python - 如何在 python 中使用 OpenCV 从图像中删除小数字和文本
- r - 节点和边缘着色产生一些问题 - 图形可视化
- swift - 在 SwiftUI 中,如何在从子视图更新共享状态数据时避免重绘父视图以避免出现导航问题?
- asp.net-core - 如何从 asp.net ef 核心中的迁移文件夹中删除特定迁移