Ниже приведен исходный код, который я написал для достижения своей цели:
@Cog.listener()
async def on_guild_join(self, guild):
db.execute('INSERT OR IGNORE INTO war_guild (GuildID) VALUES (?)', self.guild.id)
self.guild = self.get_guild(db.record('SELECT GuildID FROM war_guild', *))
existing_text_channel = [(GuildChannel.name, GuildChannel.id) for '(#text channels)' in self.guild]
existing_voice_channel = [(GuildChannel.name, GuildChannel.id) for '(#voice channels)' in self.guild]
db.multiexec('INSERT OR IGNORE INTO channels VALUES (?, ?, text)', (channel_name, channel_id) for chan in existing_text_channel)
db.multiexec('INSERT OR IGNORE INTO channels VALUES (?, ?, voice)', (channel_name, channel_id) for chan in existing_voice_channel)
Вот мой вопрос
- Подходит ли «self.guild.id» в третьей строке для получения идентификатора гильдии?
- Я не понял, как работать с классом «guildchannel», поэтому может ли кто-нибудь показать мне, как это сделать, изменив что-то в строках 5 и 6?
from os.path import isfile
from sqlite3 import connect
DB_PATH = "./data/db/database.db"
BUILD_PATH = "./data/db/build.sql"
cxn = connect(DB_PATH, check_same_thread=False)
cur = cxn.cursor()
def record(command, *values):
cur.execute(command, tuple(values))
return cur.fetchone()
def execute(command, *values):
cur.execute(command, tuple(values))
def multiexec(command, valueset):
cur.executemany(command, valueset)