Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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聊天机器人:制作情绪计数器_Python_Discord_Discord.py - Fatal编程技术网

Python Discord聊天机器人:制作情绪计数器

Python Discord聊天机器人:制作情绪计数器,python,discord,discord.py,Python,Discord,Discord.py,我想为我的不和谐聊天机器人做一个情绪计数器。此变量应影响对用户的响应。到目前为止,我用python编写了两本词典,一本叫做responses,另一本叫做侮辱。响应非常简单,如果用户发送了字典中的消息,bot将进行响应。每次你侮辱机器人时,侮辱字典都会从可变情绪中减去一个设定值。我写了一个if语句试图减少一点情绪,但每当我试图侮辱机器人时,机器人都不会对我说任何话。请帮忙。请记住,这不是所有的代码,我愿意提供一个更深入的解释,我有什么问题 @client.event async def on_me

我想为我的不和谐聊天机器人做一个情绪计数器。此变量应影响对用户的响应。到目前为止,我用python编写了两本词典,一本叫做responses,另一本叫做侮辱。响应非常简单,如果用户发送了字典中的消息,bot将进行响应。每次你侮辱机器人时,侮辱字典都会从可变情绪中减去一个设定值。我写了一个if语句试图减少一点情绪,但每当我试图侮辱机器人时,机器人都不会对我说任何话。请帮忙。请记住,这不是所有的代码,我愿意提供一个更深入的解释,我有什么问题

@client.event
async def on_message(message) :
    content = message.content.upper()
    mood = 2
    if content in responses:
        if mood <= 0:
            await client.send_message(message.channel, responses[content]["RANG"])
        if mood == 1:
            await client.send_message(message.channel, responses[content]["ANG"])
        if mood == 2:
            await client.send_message(message.channel, responses[content]["NEU"])
        if mood == 3:
            await client.send_message(message.channel, responses[content]["HAP"])
        if mood == 4:
            await client.send_message(message.channel, responses[content]["RHAP"])
    if content in insults:
        mood = mood - 0.25
        if mood <= 0:
            await client.send_message(message.channel, insults[content]["RANG"])
        if mood == 1:
            await client.send_message(message.channel, insults[content]["ANG"])
        if mood == 2:
            await client.send_message(message.channel, insults[content]["NEU"])
        if mood == 3:
            await client.send_message(message.channel, insults[content]["HAP"])
        if mood == 4:
            await client.send_message(message.channel, insults[content]["RHAP"])
@client.event
异步def on_消息(消息):
content=message.content.upper()
情绪=2
如果回答中包含以下内容:

如果mood你有奇怪的代码,因为你一直在第4行设置
mood=2

@client.event
async def on_message(message) :
    content = message.content.upper()

    mood = 2 # you hard-code your mood here!

    if content in responses: # might enter here

        if mood <= 0: # mood = 2, so won't enter here
            await client.send_message(message.channel, responses[content]["RANG"])

        if mood == 1: # mood = 2, so won't enter here
            await client.send_message(message.channel, responses[content]["ANG"])

        if mood == 2: # mood = 2, so ALWAYS here!
            await client.send_message(message.channel, responses[content]["NEU"])

        if mood == 3: # mood = 2, so won't enter here
            await client.send_message(message.channel, responses[content]["HAP"])

        if mood == 4: # mood = 2, so won't enter here
            await client.send_message(message.channel, responses[content]["RHAP"])

    if content in insults: # might enter here
        mood = mood - 0.25 # mood was 2, not it is 1.75

        if mood <= 0: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["RANG"])

        if mood == 1: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["ANG"])

        if mood == 2: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["NEU"])

        if mood == 3: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["HAP"])

        if mood == 4: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["RHAP"])
让情绪全球化 您的
情绪每次都会被重置。要避免这种情况,请尝试:


我把心情硬编码为两点开始,因为那是一个“中性”点。每当机器人受到侮辱时,我希望它减去情绪的0.25。因此,如果机器人受到足够的侮辱,情绪就会下降。谢谢你告诉我如何处理情绪反应。好的,那么你可能想让
情绪变量更全局,并在每次收到新的反应时更新它。。。现在,每次进入函数时,都会将心情重置为
2
。在我提问之前,我尝试使变量更全局化,但似乎不起作用。每当我测试它时,它都会说局部变量mood是在赋值之前引用的。我认为它认为我试图在函数中声明变量,但事实并非如此。而且,现在每当我侮辱它时,它都会工作并响应,但情绪不会下降,因为每当调用函数时,它都会重置。有什么建议吗?你能把行
mood=2
放在函数之外(即在行
@client.event
之前)吗?
    if content in insults: # might enter here
        mood = mood - 0.25 # mood was 2, now it is 1.75

        if mood <= 0: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["RANG"])

        elif mood <= 1: # mood = 1.75, so won't enter here
            await client.send_message(message.channel, insults[content]["ANG"])

        elif mood <= 2: # mood = 1.75, so ENTER HERE
            await client.send_message(message.channel, insults[content]["NEU"])

        elif mood <= 3: # elif, so skipped
            await client.send_message(message.channel, insults[content]["HAP"])

        elif mood <= 4: # elif, so skipped
            await client.send_message(message.channel, insults[content]["RHAP"])
mood = 2
@client.event
async def on_message(message) :
    content = message.content.upper()

    global mood

    if content in responses:
        .
        .
        .