#๐Ÿ”’ how to get vc by id

31 messages ยท Page 1 of 1 (latest)

thorny vapor
#

I got a dot by commands.bot all intents and i copied the id of a vc i want to get all members of the channel but when i do bot.get_channel(id).members i get Attribute error specifically NoneType object has no attribute member

ivory bronzeBOT
#

@thorny vapor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dry chasm
#

to use bot.get_channel, it must be stored in the bot cache which is unreliable. instead try to use guild.get_channel with a guild object either from ctx.guild or something similar

thorny vapor
thorny vapor
#

not quite it uses a module that works only on main so i got no idea how to do this

#
bot=commands.Bot(command_prefix=".",intents=discord.Intents.all())

def check(t):
    with mcrcon.MCRcon(HOST,PWD,PORT) as server:
        while True:
            members=bot.get_channel(1226117248154861572).members
            names=[member.nick.lower() for member in members if member.nick]
            print("ran")
            players=server.command("list")
            players=players.split(": ")[1].split(", ")
            print(players)
            for player in players:
                if player.lower() not in names:
                    server.command(f"kick {player} Go to Mc server voice chat")
            time.sleep(t)
check(10)
bot.run("
#

now that i see i dont even run the bot but how the hell would i do this?

dry chasm
#

using bot.get_guild would be better since it's not just stored in cache

thorny vapor
#

the giuld is None prob bc the bot aint running but how do i run the bot and run the loop on main at once?

#

i have to go so its hard to test from my phone but ill try test from now but i can

dry chasm
#

the issue is that python only allows one thread per program

#

unless i am being dumb

#

you can only run one loop at a time

#

I would just turn the check function into a task loop

thorny vapor
thorny vapor
#

So if i do it as a task loop u say it might work?

dry chasm
#

yeah probably

#

I gtg its 12:35 AM

#

and I have stuff tomorrow

#

or I guess today

thorny vapor
#

Also my other idea would have been to rename threads so it thinks it runs on main

dry chasm
#

that is slightly cursed

thorny vapor
dry chasm
#

bye

#

perhaps ask some of the nice folks in #python-discussion to come here and help

thorny vapor
#

!solved

ivory bronzeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.