import discord
from discord.ext import commands
from discord.utils import get
bot = commands.Bot(command_prefix = '!', help_command = None)
@bot.event
async def on_ready():
print(f"-----\nLogged in as: {bot.user.name} : {bot.user.id}")
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="Heavy Dirt"))
channel = bot.get_channel(976185018428837928)
members_int = len(ctx.guild.members)
await channel.edit(name = members_int)
@bot.event
async def on_member_join(member, ctx):
members_int = len(ctx.guild.members)
channel = bot.get_channel(976185018428837928)
embed=discord.Embed(title=f"Welcome {member.name}", description=f"Thanks for joining the Walt Ribeiro Discord!")
await channel.edit(name = members_int)
await channel.send(embed=embed)
@bot.event
async def on_member_remove(ctx):
members_int = len(ctx.guild.members)
channel = bot.get_channel(976185018428837928)
await channel.edit(name = members_int)```
#channel.edit not working
1 messages · Page 1 of 1 (latest)
Is there an error?
line 13, in on_ready
members_int = len(ctx.guild.members)
NameError: name 'ctx' is not defined
let me go look a the api doc agaon
use bot.get_guild(<guild_id>).members and it should work
or channel.category.guild.members if you want to retrieve guild members from the guild channel
Or just channel.guild.members should work
owh ok
but i dont see anything documented about that property on the docs
Category can be None
And GuildChannel (the base class of TextChannel) does have a .guild
https://docs.pycord.dev/en/master/api.html#guildchannel
owh