Discord.py 名称';用户';未定义提及
当一个用户ping另一个用户时,我正在尝试获取!让用户提及并在数据库中添加一个点!虽然用户没有定义!并且不能为用户注册任何被ping的点Discord.py 名称';用户';未定义提及,discord.py,Discord.py,当一个用户ping另一个用户时,我正在尝试获取!让用户提及并在数据库中添加一个点!虽然用户没有定义!并且不能为用户注册任何被ping的点 import sqlite3 from discord.ext import commands client = commands.Bot(command_prefix = "ping") POINTS = 0 @client.event async def on_ready(): db = sqlite3.connect(&
import sqlite3
from discord.ext import commands
client = commands.Bot(command_prefix = "ping")
POINTS = 0
@client.event
async def on_ready():
db = sqlite3.connect("ping.sqlite")
cursor = db.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS main(
user_id TEXT,
points INTERGER
)
''')
print("Looking for Pings!")
@client.event
async def on_message(message):
USER = user.mention.id
db = sqlite3.connect("ping.sqlite")
cursor = db.cursor()
cursor.execute(f"SELECT user_id FROM main WHERE user_id = {USER}")
result = cursor.fetchone()
if result is None:
sql = ("INSERT INTO main(user_id, points) VALUES(?,?)")
val = (USER, POINTS)
elif result is not None:
sql = ("UPDATE main SET channel_id = ? WHERE guild_id = ?")
val = (ctx.guild.id, channel.id)
cursor.execute(sql, val)
db.commit()
cursor.close()
db.close()
client.run(TOKEN)
您可以使用这个简单的if语句来查找消息中是否有任何用户被ping!并且位于该特定消息中所有ping用户的列表类型中
您还可以遍历消息。提及
以获取所有ping用户
if len(message.mentions) > 0:
all_pinged_users = [user for user in message.mentions]
#it will give all pinged user object in all_pinged_users and you can do anything with that!
else:
#no user is pinged