import os
from discord import FFmpegPCMAudio
from discord.ext.commands import Bot
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('OTY2MDQ5MjA1ODg4MDk0MjY4.Yl8Fbw.k3ftJGOLznBIFmdnaFCNd73qaEk')
PREFIX = os.getenv('!')
client = Bot(command_prefix = list(PREFIX))
@client.event
async def on_ready():
print('Nichijou Shuffle Bot Ready')
@client.command(aliases=['p', 'play'])
async def play(ctx, url: str = 'https://node-33.zeno.fm/tncreqmcwnhvv?zs=tdK49JAMSyu6lo3su_Wf-A&rj-tok=AAABgEq0dCAA2dBg3bs1EtEs7Q&rj-ttl'):
channel = ctx.message.author.voice.channel
global player
try:
player = await channel.connect()
except:
pass
player.play(FFmpegPCMAudio('https://node-33.zeno.fm/tncreqmcwnhvv?zs=tdK49JAMSyu6lo3su_Wf-A&rj-tok=AAABgEq0dCAA2dBg3bs1EtEs7Q&rj-ttl'))
@client.command(aliases=['s', 'stop'])
async def stop(ctx):
player.stop()
client.run(TOKEN)
I'm trying out this discord bot that plays music through a stream link. The error is happening in line 11. Credit to davestsomewhere for the code. I didn't modify the code at all but it keeps showing me the "TypeError: 'NoneType' object is not iterable" error. Don't know how to code but I think this is the only place where I can get an answer.
CodePudding user response:
It comes from the PREFIX
that is equal to None
. Thus the problem lies at the initialization of the PREFIX
.
os.gentenv()
returns the value of the environment variable key if it exists otherwise returns the default value. I don't know what you are trying to achieve with os.getenv('!')
, but either the value associated with this key is None
, either the key doesn't exist and the default value is in your case set to None
.
CodePudding user response:
the issue can be replicated in this minimal example:
import os
PREFIX = os.getenv('!')
list(PREFIX)
The environment variable !
is not set, PREFIX then is None
and making a list out of it is not possible. I'm not sure what should be in the environment variable and !
seems like a uncommon name to me.