Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.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
message.content到json文件python discord bot_Python_Json_Bots_Message_Discord - Fatal编程技术网

message.content到json文件python discord bot

message.content到json文件python discord bot,python,json,bots,message,discord,Python,Json,Bots,Message,Discord,我有一个json文件,它存储了人们的权力,我试图发出一个命令,直接赋予权力,而无需编辑json文件: if message.content.lower().startswith('addpower'): text_in = message.content text_out = text_in[text_in.find("(") + 1:text_in.find(")")] for user in message.mentions:] try:

我有一个json文件,它存储了人们的权力,我试图发出一个命令,直接赋予权力,而无需编辑json文件:

if message.content.lower().startswith('addpower'):
    text_in = message.content
    text_out = text_in[text_in.find("(") + 1:text_in.find(")")]

    for user in message.mentions:]
        try:
            user_add_power(user.id, int(text_out))
            await Bot.send_message(message.channel, "add {} power to {}".format(text_out, user.name))
        except: None
user\u add\u power
是另一个命令的一部分,它为我的服务器中键入的每个人提供电源

根据我的命令,要给人权力,我需要键入
“addpower@username(100)”
@username
人100权力

我遇到了问题:
text\u out=text\u in[text\u in.find(“”+1:text\u in.find(“”))
。 我想删除
()
,只需键入
“addpower@username 100”
即可为
@username
人员提供100个权限。
我该怎么做?

您可以通过以下方式找到
文本的最后一个单词:

text_out = text_in.split()[-1]
split()将字符串剪切为单词:

>>> text_in = "addpower @username 100"
>>> text_in.split()
['addpower', '@username', '100']
>>> text_in.split()[-1]
'100'