如何通过特定的通道名称(NOT ID)python更新我的成员计数



我已经尝试在我的bot中循环。循环是为了更新成员计数器。我想仔细检查一下这是否正确,因为它没有更新统计数据。频道本身可以通过命令制作,这是我遇到麻烦的更新部分任何帮助都将不胜感激。显示没有错误,我真的很困惑。提前谢谢!

import nextcord
from nextcord.ext import commands, tasks
from nextcord.webhook import async_
class stats(commands.Cog):
def __init__(self,client):
self.client = client


@tasks.loop(minutes=1)
async def looped_task(self,):
text_channel_list = []
stats = len(self.guild.members)
channel = self.client.get_channel.startswith('Members: ')
for guild in self.client.guilds:
for channel in guild.text_channels:
text_channel_list.append(channel)
if channel == True:
await channel.edit(channel, name = f"Members: {stats}")


@commands.command()
async def stat(self, ctx):
channel = self.client.get_channel.startswith('Members')
stats = len(ctx.guild.members)
await ctx.guild.create_voice_channel(name=f"Members:{stats}", category=None)
await ctx.send(f"Your Server has {stats} members")

def setup(client):
client.add_cog(stats(client))

您开始执行任务了吗?如果没有,它当然不会更新。当使用循环的任务时,需要按照文档中的说明启动它们。特别是task.start((

您可以在Cog中添加这段代码,以便在Cog本身准备就绪时启动它。

@commands.Cog.listener()
async def on_ready(self):
self.looped_task.start()

最新更新