Discord.py 当我尝试向不和谐频道发送消息时,它会重复该消息

Discord.py 当我尝试向不和谐频道发送消息时,它会重复该消息,discord.py,Discord.py,当我的discord bot尝试向discord服务器发送消息时,它会重复该消息 主程序代码: if message.content == "-play": player = message.author player_created = "True" if player in players: pass else: players.append(player) invento

当我的discord bot尝试向discord服务器发送消息时,它会重复该消息

主程序代码:

if message.content == "-play":
    player = message.author
    player_created = "True"
    if player in players:
        pass
    else:
        players.append(player)
        inventories.update({player.name: []})
        positions.update({player.name: "start location"})
# message not -play
else:
    # if a player exists
    if player_created == "True":
        if positions[player.name] == "start location":
            text = main3_functions.example_room(inventories)
        await message.channel.send(text)

它会重复,因为bot会将自己的消息作为“命令”接收。因此,它会检查消息内容是否正确,但不可能正确。因此,您要做的是添加到else语句中

如果message.user.id!=bot.user.id:

if message.author == client.user:
    return

这应该添加在代码的顶部,这样它就可以忽略来自bot本身的消息。

不要在问题中发布图片,应该将其添加到问题本身的代码块中。请编辑您的问题欢迎使用堆栈溢出!你的问题缺少很多信息。为了改进您的问题,请查看。添加您拥有的所有可能有助于我们的信息,但请尽量简短。如果您对代码有疑问,请包括代码。您还可以通过这篇短文了解有关堆栈溢出的更多信息。还提供一个测试环境,以便陌生人可以测试您的代码并重现您的错误。