【发布时间】:2022-10-04 20:18:29
【问题描述】:
我想用 1 个 AND 运算符检查 2 个条件。
我尝试了以下方法:
JavaScript:
a = True
b = False
x = 3
if (x == 2 & a == true | b == false){
return;
}
带调整括号:
a = True
b = False
x = 3
if (x == 2 & (a == true | b == false)){
return;
}
[ console log false ]
Python:
a = True
b = False
x = 3
if x == 2 & a == true or b == false:
return
带调整括号:
a = True
b = False
x = 3
if x == 2 & (a == true or b == false):
return
[ console log false ]
我的原始 Python 代码:
import discord
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
client = discord.Client(intents=intents)
nomes = ['filho', 'franguinho', 'franguinho jr', 'frango jr'] # NAMES OF THE BOT
@client.event
async def on_ready():
print('Logged')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="ACTIVITY"))
async def gsend(msg):
client.send_message(client.get_channel("ID OF CHANNEL"), msg)
@client.event
async def on_message(message):
mensagem = message.content.lower()
pessoa = message.author
pai = 'ID OF USER'
if pessoa.id == pai and mensagem in nomes or mensagem in "<@"+str(client.user.id)+">":
await message.channel.send('MESSAGE TO TALK')
client.run('TOKEN OF DISCORD BOT')
带调整括号:
if pessoa.id == pai and (mensagem in nomes or mensagem in "<@"+str(client.user.id)+">"):
await message.channel.send('MESSAGE TO TALK')
【问题讨论】:
-
在 python 中,
&是一个明智的运算符,使用and代替它。 -
我已经试过了,还是不行
-
不要使用; &和python中的小写true或false
-
我们当然不是来教你语言本身的,最好看the Python docs for operators并提出具体问题
-
我们当然是来教我的,这是一个论坛
标签: python discord.py operators