Anush Shetty
Anush Shetty

Reputation: 77

How to fix 'Path' is not defined in discord.py?

import discord
from discord.ext import commands, tasks
import ctypes
import ctypes.util
import logging

# Check and Load Opus Library

print("ctypes - Find opus:")
a = ctypes.util.find_library('opus')
print(a)
 
print("Discord - Load Opus:")
b = discord.opus.load_opus(a)
print(b)
 
print("Discord - Is loaded:")
c = discord.opus.is_loaded()
print(c)



# Setup Wave File

number_txt_file = Path.cwd() / 'number.txt'
number_txt_file.touch(exist_ok=True)
number = int(number_txt_file.open('r').read() or 0)
waves_folder = (Path.cwd() / 'recordings')
waves_file_format = "recording{}.wav"
waves_folder.mkdir(parents=True, exist_ok=True)

# The rest of my code

# Bot Client ID

bot.run('MyToken')

This is my code to get audio from a VC. But there's an error:

      File "main.py", in <module>
number_txt_file = Path.cwd() / 'number.txt'
NameError: name 'Path' is not defined

I got it working earlier. The purpose is to record audio from a voice channel. But now I am getting this error. How to fix this?

Upvotes: 0

Views: 132

Answers (2)

x0xRumbleLorex0x
x0xRumbleLorex0x

Reputation: 121

Get the current working directory:

import os

os.getcwd()

In your case:

import os

number_txt_file = os.getcwd() + 'number.txt'

Upvotes: 1

Kemp
Kemp

Reputation: 3649

You need to import Path from the pathlib module.

Upvotes: 1

Related Questions