Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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在dm中发送消息?_Python_Discord.py - Fatal编程技术网

Python 如何检测单词,然后使用discord.py在dm中发送消息?

Python 如何检测单词,然后使用discord.py在dm中发送消息?,python,discord.py,Python,Discord.py,我正在尝试检测YouTube视频链接何时通过dm发送,是否可以这样做,如果可以,如何做?如果我的理解是正确的,这将对您有所帮助。我试图让您尽可能清楚地按照自己的意愿修改代码 client = discord.Client() #Discord Client @client.event async def on_message(message): #Event handler for income messages if message.author == client.user: #

我正在尝试检测YouTube视频链接何时通过dm发送,是否可以这样做,如果可以,如何做?

如果我的理解是正确的,这将对您有所帮助。我试图让您尽可能清楚地按照自己的意愿修改代码

client = discord.Client() #Discord Client

@client.event
async def on_message(message): #Event handler for income messages
    if message.author == client.user:  #Stopping the bot from reading its on message
        return None 
    
    word_to_check = 'example' #Word that you want to check in a string
    response = 'this is the response'

    if word_to_check in message.content:    
        await message.channel.send(response) #This responds to the channel the message containing "word_to_check" came from

你试过什么吗?@griffin_cosgrove我对discord.py没有太多经验,所以我想不出什么可以尝试的,对不起,这个问题是一堆问题。您正在询问如何检测消息何时发送,检查它是否为dm,然后检查它是否包含youtube链接。这些都是单独的问题,您应该尝试实现这些问题,如果代码不起作用,则应针对每个问题提出问题。很可能这三个问题都已经有了关于StackOverflow的答案