Discord.py始终会发送相同的错误响应

时间:2020-08-16 21:58:49

标签: python discord bots discord.py

我确实很努力地尝试使用 Discord.py 遇到了问题,但是即使我想了很多解决办法,也无法获得预期的结果。我将尝试包括所有这些。

所以让我总结一下问题。

首先,这是我遇到问题的代码:

if message.content.startswith("lerconics"):
                
            print(usr_msg)
            if usr_msg=="sa":
                msg="as"

                cmd="sa"
                cmds.append(cmd)

            if usr_msg=="merhaba":
                msg="merhaba {0.user.mention}"

                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg=="lerconics":
                msg="efendim {0.user.mention}?"
                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg=="yardım":
                msg="as"
     
                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg == "dm":
                msg="İşte. Dm'ini kontrol etmeyi unutma. :)"
                await message.author.send(usr_arg)
                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg == "":
                msg="Umm.. Why did u call me for nothing? these people... Please tell your request in the message you call me. Or else I'm so lazy. lol"
            else:
                msg=" There is no command like that! To get a list of all the available commands, use the command help!"
            
            await message.channel.send(msg)
         

它发出消息没有这样的命令!要获取所有可用命令的列表,请使用命令帮助!您写为“ lerconics ....”的内容。

因此,我确实确实认为这里的主要问题是编译器绕过了所有的if子句,并涉及到else子句,但是我在每个if中使用了一条print命令进行了测试,并进行了打印。但是它仍然给出相同的结果。

我什至认为问题可能出在下面的等待部分,因为它确实使我DM ..我真的不知道。

注意:如果您认为我没有声明变量,则变量没有问题。我只是重要的一环。如果您认为需要所有代码,请查看文章的底部。

所有代码:

#Welcome to our bot, Lerconics! (important links coming soon)

#I am a Discord bot coded with using Python 3.8 by LERCDSGN manager nicknamed Programmer Potato (I just made it up lol)!

#Enjoy our bot and if you're interested in the codes, there are notes meaning some easy steps for you to follow! Let's start, then. Remember, notes that are in a line with a code or said nfm(note for me) at the beginning, they are notes for my creator!


#--------------------------------------------------------

#---------  STEP 1: Importing Needed Modules  -----------


#Firstly, I have to Import Discord or else I cannot connect to the app.

print("Importing Discord...")

import discord

print("Succesfully Done.")

#-- STEP 2: Declaring Variables And Defining Functions --


#------     STEP 2A : Declaring Variables          ------

#This is my Token. It's like a credit card number or a password of mine so if it's stolen, my life is in danger because anyone who has this would be able to control me!

TOKEN = 'NzQzNDYxODY0MjQyOTM3OTU3.XzVA0Q.DICCboiztcEb3iFpJzcWauF8Kp8'

#This step makes it simple when making something by referencing the client!

client = discord.Client()

#------     STEP 2B : Defining Functions        ------


#Check when an event happens...

@client.event

async def on_message(message):
    MSG=""
    cmd=""
    cmds=[]
    cmd_num=1
    usr_arg="Please enter an argument for me to apply the command on, like a message to send!"
    chn = message.channel
    usr_msg=message.content[10:]
    if ":" in usr_msg:
        usr_arg=usr_msg[usr_msg.find(":")+1:]
        usr_msg=usr_msg[:usr_msg.find(":")]
        
    if message.author == client.user:
        return
    else:
    
    #Sadly and happily, I won't be able to reply myself to prevent a possible loop!
        if message.content.startswith("lerconics"):
                
            print(usr_msg)
            if usr_msg=="sa":
                msg="as"

                cmd="sa"
                cmds.append(cmd)

            if usr_msg=="merhaba":
                msg="merhaba {0.user.mention}"

                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg=="lerconics":
                msg="efendim {0.user.mention}?"
                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg=="yardım":
                msg="as"
     
                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg == "dm":
                msg="İşte. Dm'ini kontrol etmeyi unutma. :)"
                await message.author.send(usr_arg)
                cmd="sa"
                cmds.append(cmd)
                
            if usr_msg == "":
                msg="Umm.. Why did u call me for nothing? these people... Please tell your request in the message you call me. Or else I'm so lazy. lol"
            else:
                msg=" There is no command like that! To get a list of all the available commands, use the command help!"
            
            await message.channel.send(msg)
    
    
    #T will check if they actually called me to not annoy others!
    
    

#when an event happens
        
@client.event

#when the code is succesfully ran

async def on_ready():
    await client.change_presence(activity=discord.Game(name='lerconics help'))
    #sends name and id of the bot in the console to confirm its running with this bot
    
    print('Enter succesfull! Logged in as the user with an \n ID of ' + str(client.user.id) + "and a name of " + str(client.user.name) + ". Go check if it worked!")

    #Sends a message in the home channel (using its ID) to tell the bot's online again in Discord.

#running the token to start
client.run(TOKEN)

1 个答案:

答案 0 :(得分:0)

(代表问题作者发布的解决方案,将其移至答案空间)

我知道了!我用“ if”制作所有代码只是一个基本问题,因此编译器读取 if,if ...,如果最后一个if不是True,则返回else!

所以我让他们成为“ elif” 和BOOM!找到了解决方案,但仍不确定。