message.content 到 json 文件 python discord bot
message.content to json file python discord bot
我有一个 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_add_power
它是另一个命令的一部分,该命令为在我的服务器中输入的每个人赋予权力。
根据我的命令,要给人们力量,我需要输入"addpower @username (100)"
给@username
人100力量。
我遇到了这个问题:text_out = text_in[text_in.find("(") + 1:text_in.find(")")]
。
我想删除 ()
并且只需要输入 "addpower @username 100"
来给 @username
人 100 的权力。
我该怎么做?
你可以这样找到text_in
的最后一个字:
text_out = text_in.split()[-1]
split() 将字符串切割成单词:
>>> text_in = "addpower @username 100"
>>> text_in.split()
['addpower', '@username', '100']
>>> text_in.split()[-1]
'100'
我有一个 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_add_power
它是另一个命令的一部分,该命令为在我的服务器中输入的每个人赋予权力。
根据我的命令,要给人们力量,我需要输入"addpower @username (100)"
给@username
人100力量。
我遇到了这个问题:text_out = text_in[text_in.find("(") + 1:text_in.find(")")]
。
我想删除 ()
并且只需要输入 "addpower @username 100"
来给 @username
人 100 的权力。
我该怎么做?
你可以这样找到text_in
的最后一个字:
text_out = text_in.split()[-1]
split() 将字符串切割成单词:
>>> text_in = "addpower @username 100"
>>> text_in.split()
['addpower', '@username', '100']
>>> text_in.split()[-1]
'100'