#channel.edit not working

1 messages · Page 1 of 1 (latest)

urban stone
#
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)```
sick tulip
#

Is there an error?

urban stone
#

line 13, in on_ready
members_int = len(ctx.guild.members)
NameError: name 'ctx' is not defined

sick tulip
#

well on_ready doesn't get context

#

you'd need a guild object to get the member count

urban stone
#

let me go look a the api doc agaon

orchid rose
#

or channel.category.guild.members if you want to retrieve guild members from the guild channel

signal obsidian
orchid rose
#

owh ok

orchid rose
signal obsidian
orchid rose
#

owh