我刚刚从 youtube 复制了这段代码:
import discord
from discord.ext import commands
import os, asyncio
#import all of the cogs
from help_cog import help_cog
from music_cog import music_cog
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='/', intents=intents)
bot.remove_command('help')
#remove the default help command so that we can write out own
async def main():
async with bot:
await bot.add_cog(help_cog(bot))
await bot.add_cog(music_cog(bot))
await bot.start(os.getenv['TOKEN'])
asyncio.run(main())
这是错误
> await bot.start(os.getenv['TOKEN'])
> TypeError: 'function' object is not subscriptable
我想我下载了所需的所有功能。 谁能帮我解决这个错误吗?
os.getenv
是一个函数,而不是一个列表(不可下标意味着你不能像数组一样索引它),你应该从更改它
os.getenv['TOKEN']
到
os.getenv('TOKEN')
假设其他一切都正确的话,它应该可以工作。