我正在尝试使用配置我的欢迎活动sqlite3。我编写了以下代码:
import discord
from discord.ext import commands, tasks
import discord.utils
import asyncio
import datetime
import sqlite3
class WelCog(commands.Cog, name='Welcome') :
def __init__(self,bot):
self.bot = bot
@commands.Cog.listener()
async def on_member_join(self,member):
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {member.guild.id}")
result = cursor.fetchone()
if result is None:
return
else:
cursor.execute(f"SELECT msg FROM main WHERE guild_id = {member.guild.id}")
result1 = cursor.fetchone()
members = len(list(member.guild.members))
mention = member.mention
user = member.name
guild=member.guild
embed = discord.Embed(color=0x0ff7dc, description=str(result1[0]).format(members=members, mention=mention, user=user, guild=guild))
embed.set_thumbnail(url=f"{member.avatar_url}")
embed.set_author(name=f"{member.name}", icon_url=f"{member.avatar_url}")
embed.set_author(name=f"{member.guild}", icon_url=f"{member.guild.icon_url}")
channel = self.bot.get_channel(id=int(result[0]))
await channel.send(embed=embed)
@commands.group(invoke_without_command=True)
async def welcome(self,ctx):
await ctx.send('Available Setup Commands: \nwelcome channel <#channel>\n welcome text <message>')
@welcome.command()
async def channel(self, ctx, channel:discord.TextChannel):
if ctx.message.author.guild_permissions.manage_messages:
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f"SELECT channel_id FROM main WHERE guild_id = {ctx.guild.id}")
result = cursor.fetchone()
我尝试了很多方法来解决这个问题,但遗憾的是我无法解决。
白猪掌柜的
相关分类