I have a program that checks if a client has connected to my server and saves them to a list. If a client connects, the discord bot needs to create a discord channel with their name, so I wrote the following code.
def connect():
while True:
try:
client, address = server.accept()
whoami = client.recv(2048).decode()
name = client.recv(2048).decode()
randomGuy = someRandomGuy(name, client, address)
print(f"[HUB] {name} has connected to server.")
randomGuys.append(randomGuy)
fileSize = os.path.getsize("saveRandomGuys.txt")
fileRead = open("saveRandomGuys.txt", "r")
lines = []
for line in fileRead:
line = line.strip("n")
lines.append(line)
print(lines)
if randomGuy.name not in lines:
with open("saveRandomGuys.txt", 'a') as file:
if fileSize == 0:
file.writelines(f"{randomGuy.name}")
file.close()
print("ClientID has been saved")
else:
file.writelines(f"n{randomGuy.name}")
file.close()
print("ClientID has been saved")
async def createChannel(message, name):
await message.guild.create_text_channel(name = '{}'.format(name))
await message.send("Channel created")
createChannel(message, name)
except RuntimeError:
print(RuntimeError)
It throws the following error when I run it:
Traceback (most recent call last):
File "c:UsersmerliAppDataLocalProgramsPythonPython312Libsite-packagesdiscordclient.py", line 449, in _run_event
await coro(*args, **kwargs)
File "C:UsersmerliDocumentsProgrammingPythonDiscord-botDiscord-controllerVersie 0.2DiscordBotHubInt.py", line 76, in on_ready
connect()
File "C:UsersmerliDocumentsProgrammingPythonDiscord-botDiscord-controllerVersie 0.2DiscordBotHubInt.py", line 60, in connect
createChannel()
TypeError: connect.<locals>.createChannel() missing 2 required positional arguments: 'message' and 'name
I just want to create a channel when I call the function, but following the other questions on this site, it seems that I need either a message or ctx variable and I don’t have either.