Python 3.x 如何让Discord bot使用用户选择的号码名称发送图像?(Python 3.5.x)

Python 3.x 如何让Discord bot使用用户选择的号码名称发送图像?(Python 3.5.x),python-3.x,bots,discord,Python 3.x,Bots,Discord,我还在学习python和编程,我陷入了一个无法解决的问题。我想发出一个命令,使机器人发送一个图像,其名称对应于用户编写的数字,例如用户编写的!图像编号22,机器人发送22.jpg。我只做了代码,从文件夹发送随机图像,但我不能进入选择。以下是我针对此问题的最新代码: elif message.content.startswith("!obrazeknr"): #missing an argument or something, idk what to make here obra

我还在学习python和编程,我陷入了一个无法解决的问题。我想发出一个命令,使机器人发送一个图像,其名称对应于用户编写的数字,例如用户编写的!图像编号22,机器人发送22.jpg。我只做了代码,从文件夹发送随机图像,但我不能进入选择。以下是我针对此问题的最新代码:

 elif message.content.startswith("!obrazeknr"): #missing an argument or something, idk what to make here
        obrazDirectoryChc = "C:/Users/Lewando54/Downloads/Localisation/English/" + liczba + ".jpg"
        await client.send_file(message.channel, obrazDirectoryChc, content=obrazName[1])

您可以在此elif语句中尝试:

msg = message.content[12:] #skips the command word and the '!' and the " "

msg = msg.split() #split the message into an array at the spaces.
#msg = ["!image_nr","22"]

if msg[0] == "!image_nr" and msg[1].isnumeric() == True:

 obrazDirectoryChc = "C:/Users/Lewando54/Downloads/Localisation/English/" + 
     liczba + ".jpg"
 await client.send_file(message.channel, obrazDirectoryChc, 
     content=obrazName[int(msg[1]])
现在,它应该发送用户请求的照片

e、 g!obrazeknr图像\u nr 22

希望这有帮助。抱歉等了这么久,我今天才看到这个

下次在programming.stackoverflow.com上发布可能是个更好的主意
它可以给你更多的帮助。

它很有效。我稍微修改了一下,效果不错。Thx用于idea:D

elif message.content.startswith('!obrazeknr'):
    msg1 = message.content #skips the command word and the '!' and the " "  
    msg1 = msg1.split() #split the message into an array at the spaces.
    #msg = ["!obrazeknr","22"]
    if msg1[0] == "!obrazeknr" and msg1[1].isnumeric() == True:
        await client.send_file(message.channel, "C:/Users/Lewando54/Downloads/Localisation/English/" + str(int(msg1[1])) + ".jpg")