Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.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 如何检测某人是否写了不和谐的内容。py_Python_Discord.py - Fatal编程技术网

Python 如何检测某人是否写了不和谐的内容。py

Python 如何检测某人是否写了不和谐的内容。py,python,discord.py,Python,Discord.py,我想让机器人检查是否有人在我的discord中的任何频道中键入了消息,然后如果它检测到机器人键入了我想让它说的内容,是否知道如何检查有人键入了内容?阅读discord文档后,我发现: import discord class MyClient(discord.Client): async def on_ready(self): print('Logged in as') print(self.user.name) print(self.u

我想让机器人检查是否有人在我的discord中的任何频道中键入了消息,然后如果它检测到机器人键入了我想让它说的内容,是否知道如何检查有人键入了内容?

阅读discord文档后,我发现:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('!hello'):
            await message.reply('Hello!', mention_author=True)

client = MyClient()
client.run('token')
只需用您的机器人令牌替换
令牌
。其余的应该不言自明

编辑:

要检测特定角色,可以执行以下操作:

if message.content.startswith('!hello'):
            if premium_subscriber_role:
                        await message.reply('Hello!', mention_author=True)

这将检查用户是否具有服务器增强程序角色,如果用户具有服务器增强程序角色,则bot将以“Hello!@username”进行回复。

说我想检查某个特定的人是否键入了任何内容,我有什么方法可以这样做吗?我更新了我的答案!谢谢你,我很抱歉再次问你,你知道有没有办法检查任何消息,无论它以什么开头,因为它说,它只会检查,如果它以什么开头!您好您可以试试这个:
message.content(“”):