热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在pythondiscordbot中标记成员

所以我在python中有这个调平系统,但是我想添加一个@tag,所以该机器人提到了进行调

所以我在python中有这个调平系统,但是我想添加一个@tag,所以该机器人提到了进行调平的成员...但是我不知道该怎么做。我已经尝试了多种方法,但是它们都不起作用。

from discord.ext import commands
import discord
import logging
import yaml
import sqlite3
import time
import random
import re
logging.basicConfig(level=logging.INFO)
bot = commands.Bot(command_prefix='l>',description='Hype Levels')
def threshold(n):
level_threshold = 5*(n**2)+50*n+100
return level_threshold
@bot.command(pass_cOntext=True)
async def rank(ctx):
try:
_,member = (ctx.message.content).split(' ',1)
member = re.sub("[^0-9]","",member)
except:
member = ctx.message.author.id
db = sqlite3.connect('users.db')
c = db.cursor()
c.execute('SELECT user.*,(SELECT count(*) FROM users AS members WHERE members.rawexp > user.rawexp) as Rank FROM users AS user WHERE id = ?',(ctx.message.author.id,))
user = c.fetchone()
db.close()
rank = str(user[6] + 1)
embed = discord.Embed(title='{}\'s Information'.format(ctx.message.author.name)) \
.set_thumbnail(url=ctx.message.author.avatar_url) \
.add_field(name='Rank',value='#' + rank) \
.add_field(name='Level',value=user[2]) \
.add_field(name='EXP',value='{}/{}'.format(user[3],threshold(user[2]))) \
.add_field(name='Raw EXP',value=user[4]) \
await ctx.send(embed=embed)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.author.bot:
return
if message.content.startswith('l>'):
await bot.process_commands(message)
return
db = sqlite3.connect('users.db')
c = db.cursor()
c.execute('SELECT * FROM users WHERE id= ?',(message.author.id,))
user = c.fetchone()
if user is None:
await message.channel.send('Looks like you\'re new! Welcome to level 1. Initializing player...')
c.execute('INSERT INTO users(id,name,level,exp,rawexp,time) VALUES(?,?,?)',message.author.name,1,time.time()))
db.commit()
db.close()
return
if message.author.name != user[1]:
c.execute('UPDATE users SET name = ? WHERE id= ?',(message.author.name,message.author.id))
if (time.time() - user[5]) > 60:
addedexp = random.randint(10,25)
exp = user[3] + addedexp
rawexp = user[4] + addedexp
c.execute('UPDATE users SET exp = ?,rawexp = ?,name = ?,time = ? WHERE id= ?',(exp,time.time(),message.author.id))
if (exp > threshold(user[2])):
level = user[2] + 1
c.execute('UPDATE users SET exp = ?,level = ? WHERE id= ?',(0,message.author.id))
await message.channel.send('Wowza! You leveled up! Your level is now **{}**.'.format(level))
db.commit()
db.close()
await bot.process_commands(message)
@bot.event
async def on_ready():
print("Hypelevels V1.1")
print("Made by: Garbodonk#6347")
print("Bot Name: " + str(bot.user.name))
print("Bot ID: " + str(bot.user.id))
await bot.change_presence(activity=discord.Streaming(name='some HYPE',url="https://www.twitch.tv/hypepixelbot",type=1))
#Initialize database.
db = sqlite3.connect('users.db')
c = db.cursor()
c.execute('CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY,name TEXT,level INT,exp INTEGER,rawexp INTEGER,time REAL)')
db.commit()
bot.run('Token')

但是我想在人们升级时添加一个@tag,以便他们被标记

if (exp > threshold(user[2])):
level = user[2] + 1
c.execute('UPDATE users SET exp = ?,message.author.id))
await message.channel.send('Wowza! You leveled up! Your level is now **{}**.'.format(level))

谁知道该怎么做?要问我问题或其他问题,只需加我不和谐即可:Garbodonk#6347


async def command(ctx,member : discord.Member,*,reason=None) :
await ctx.send(f" can place text here if you want {member.mention} can place text here as well")```
I hope this helps.

推荐阅读
author-avatar
iwasafool
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有