4 回答

TA貢獻2065條經驗 獲得超14個贊
有點棘手:
b = [int(digit) for digit in ''.join((str(item) for item in a))] print(b)
輸出:
[1, 4, 1, 2, 1, 0, 8]

TA貢獻1872條經驗 獲得超4個贊
您可以使用
@client.command()
@commands.has_permissions(**permission needed**=True)
這將只允許具有特定權限的人執行該命令(錯誤消息選項)?;蛘?,如果您只想要具有某個角色的人員,您可以使用 if message.author.role.id == **role id**: 或 if ctx.message.author.role.id == **role id**:。這是一個示例代碼:
@client.event
async def on_message(message):
link = ["https://"]
for word in link:
if message.content.count(word) > 0:
if message.author.role.id == 706694479847096381:
return
else:
print(f'{message.author}({message.author.id}) Sent an link')
await message.delete()
此代碼允許機器人在發送鏈接時忽略具有該角色的人員。

TA貢獻1895條經驗 獲得超3個贊
這是一種不使用字符串作為中介的替代方法:
test_list = [14, 12, 10, 8]
output_list = []
for number in test_list:
if number < 10:
output_list.append(number)
else:
output_list.extend([number // 10, number % 10])
print(output_list)
添加回答
舉報