Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py检查消息和内容_Python_Discord_Discord.py - Fatal编程技术网

Python Discord.py检查消息和内容

Python Discord.py检查消息和内容,python,discord,discord.py,Python,Discord,Discord.py,有没有办法检查用户是否发送两次消息(相同内容),然后在10秒内不让他发送消息?10秒是一个示例您可以将消息作为变量保存在主代码中,然后在下一条消息中检查上一条消息是否与当前消息相同,并添加角色使其静音,然后在10秒后删除该角色 例如: import asyncio first_message = True bot.event async def on_message(message): global msg msg = message first_message =

有没有办法检查用户是否发送两次消息(相同内容),然后在10秒内不让他发送消息?10秒是一个示例

您可以将消息作为变量保存在主代码中,然后在下一条消息中检查上一条消息是否与当前消息相同,并添加角色使其静音,然后在10秒后删除该角色

例如:

import asyncio

first_message = True

bot.event
async def on_message(message):
    global msg
    msg = message
    first_message = False

    if not first_message and msg == message:
        await message.delete()
        role = await bot.get_role(ROLE_ID)
        await message.author.add_role(role)

        await asyncio.sleep(10)
        
        await message.author.remove_role(role)

因此,您需要创建一个例如静音角色,该角色的ID是您作为角色输入的。\u ID

您在代码中尝试了什么吗?没有,我没有尝试任何东西。首先,您必须更具体地说,发送两次消息(重复消息),说明您希望检查的间隔。你想做什么?这里没有人会给您完整的代码来启动
将每个用户的最新消息保存到一个JSON文件中,并在其中迭代以查找重复消息
欢迎使用堆栈溢出!请阅读,并提供一个“为我实现此功能”是本网站的主题。你必须做出诚实的尝试,然后问一个关于你的算法或技术的具体问题。如果你不知道从哪里开始,你需要查阅一本教程或与导师交谈。堆栈溢出是寻求一般建议的错误位置