Python discord.py Cog//如何将消息发送到特定通道 @commands.Cog.listener() _消息上的异步定义(self,message): 通道=self.client.get_通道(797863482380124170) 如果对话频道中的message.channel.id: stats=leveling.find_one({“id”:message.author.id}) 如果不是message.author.bot: 如果stats为None: newuser={“id”:message.author.id,“xp”:100} 调平。插入一个(新用户) 其他: xp=统计数据[“xp”]+100 leveling.update_one({“id”:message.author.id},{“$set”:{“xp”:xp}) lvl=0 尽管如此: 如果xp
这是我的代码,但等待消息。频道。发送无效。请帮助我Python discord.py Cog//如何将消息发送到特定通道 @commands.Cog.listener() _消息上的异步定义(self,message): 通道=self.client.get_通道(797863482380124170) 如果对话频道中的message.channel.id: stats=leveling.find_one({“id”:message.author.id}) 如果不是message.author.bot: 如果stats为None: newuser={“id”:message.author.id,“xp”:100} 调平。插入一个(新用户) 其他: xp=统计数据[“xp”]+100 leveling.update_one({“id”:message.author.id},{“$set”:{“xp”:xp}) lvl=0 尽管如此: 如果xp,python,discord.py,Python,Discord.py,这是我的代码,但等待消息。频道。发送无效。请帮助我 我尝试了很多方法,但都不起作用。等待频道。send()应该可以。您可以在此处阅读更多内容:我认为通道不起作用,因为OP已经定义了channel=self.client.get\u通道(797863482380124170),该通道不一定与发生消息事件的通道相同。 @commands.Cog.listener() async def on_message(self, message): channel = self.client.get_
我尝试了很多方法,但都不起作用。
等待频道。send()
应该可以。您可以在此处阅读更多内容:我认为通道不起作用,因为OP已经定义了channel=self.client.get\u通道(797863482380124170)
,该通道不一定与发生消息事件的通道相同。
@commands.Cog.listener()
async def on_message(self, message):
channel = self.client.get_channel(797863482380124170)
if message.channel.id in talk_channel:
stats = levelling.find_one({"id": message.author.id})
if not message.author.bot:
if stats is None:
newuser = {"id": message.author.id, "xp": 100}
levelling.insert_one(newuser)
else:
xp = stats["xp"] + 100
levelling.update_one({"id": message.author.id}, {"$set": {"xp": xp}})
lvl = 0
while True:
if xp < ((50 ** (lvl ** 2)) + (50 * lvl)):
break
lvl += 1
# lvl += 1
xp -= ((50 * ((lvl - 1) ** 2)) + (50 * (lvl - 1)))
if xp == 0:
await message.channel.send(f"{message.author.mention} Lvl Up!")