【发布时间】:2021-02-26 03:17:27
【问题描述】:
我为 Discord 机器人设置了一个非常简单的命令。这应该是为了响应!positions 命令,检查作者和频道,如果作者是我,频道是我与机器人的 DM 频道,做一些事情(比如发送回复消息)。
我的帐户 ID 是 285538805728149504。当命令!positions 运行时,它会输出:
Author ID 285538805728149504
DM channel 814250853669666887
Current channel 814250853669666887
您可以看到它打印出的作者 ID 完全与我要与之比较的硬编码用户 ID 相同。您还可以看到比较的两个频道 ID 完全相同相同。
但是,它不会通过任何 if 语句。
代码如下:
@commands.command()
async def positions(self, ctx):
positions_file = Path("positions.json")
positions = json.loads(positions_file.read_text())
message_author = ctx.message.author.id
print("id " + str(message_author))
print("dm channel " + str(ctx.message.author.dm_channel.id))
print("Current channel " + str(ctx.message.channel.id))
my_id = "285538805728149504"
if message_author == my_id:
print("Author ID is my ID")
if ctx.message.author.dm_channel.id == ctx.message.channel.id:
print("Channel ID is my DM channel")
await ctx.message.author.dm_channel.send("reply")
为什么我不能成功比较这些数字?
【问题讨论】:
标签: python discord discord.py