这个不和谐的音乐机器人代码有什么问题

问题描述 投票:0回答:1

我刚刚从 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

我想我下载了所需的所有功能。 谁能帮我解决这个错误吗?

python discord discord.py bots
1个回答
4
投票

os.getenv
是一个函数,而不是一个列表(不可下标意味着你不能像数组一样索引它),你应该从

更改它
os.getenv['TOKEN']

os.getenv('TOKEN')

假设其他一切都正确的话,它应该可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.