400 仅来自两个返回字符串的 if 语句之一的错误请求(错误代码:50006)

问题描述 投票:0回答:1

在更新不和谐机器人时,我无法实现它可以响应的新命令,第一个命令可以正常工作,而第二个命令只能响应 400 Bad Request(错误代码:50006)。

import random

def handle_response(message) -> str:
    p_message = message.lower()

    if "gub" in p_message:
        return "GUB."
    
    if "roll" in p_message:
        result = random.randrange(1,6)
        return f"Rolling a d6...\nYou rolled a {str(result)}!"
import discord
import responses


intents = discord.Intents.default()
intents.message_content = True


async def send_message(message, user_message, is_private):
    try:
        response = responses.handle_response(user_message)
        await message.author.send(response) if is_private else await message.channel.send(response)
    except Exception as e:
        print(e)

def run_discord_bot():
    token = "nope"
    client = discord.Client(intents=intents)

    @client.event
    async def on_ready():
        print(f'{client.user} is now running.')

    
    @client.event
    async def on_message(message):
        if message.author == client.user:
            return
        
        username = str(message.author)
        user_message = str(message.content)
        channel = str(message.channel)

        print(f"{username} said: '{user_message}' ({channel})")
        

        if user_message[:4] == 'GUB!':
            user_message = user_message[4:]
            await send_message(message, user_message, is_private=False)
        else:
            pass



    client.run(token)

我尝试将第二个字符串设为像第一个字符串一样的简单的 3 个字母字符串,完全注释掉第一个字符串,更改所有变量的名称以确保变量名称和搜索的内容不冲突,每个它返回相同响应的时间。

令人困惑地更改用户消息前缀字符串和第一个 if 语句字符串一个字母会破坏前缀检测,对新字符串或旧字符串不起作用。

python discord.py
1个回答
0
投票

这是一种非常古老且过时的机器人命令制作方式。这是来自discord.py GitHub repositoryexample,关于基本的discord bot实现,这将对你有很大帮助。这是discord.py 文档

© www.soinside.com 2019 - 2024. All rights reserved.