Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为两件事运行令牌_Python_Discord.py - Fatal编程技术网

Python 为两件事运行令牌

Python 为两件事运行令牌,python,discord.py,Python,Discord.py,因此,我正在尝试为我的dis服务器创建一个bot,但是我的代码的两部分需要令牌来运行它们,但是无论我如何努力,我都无法使用令牌来运行这两部分 我的代码: intents = discord.Intents(members=True, messages = True, guilds=True,) client = discord.Client(intents=intents) BOT_PREFIX = ("!") bot = commands.Bot(comm

因此,我正在尝试为我的dis服务器创建一个bot,但是我的代码的两部分需要令牌来运行它们,但是无论我如何努力,我都无法使用令牌来运行这两部分

我的代码:

intents = discord.Intents(members=True, messages = True, guilds=True,)


client = discord.Client(intents=intents)
    
BOT_PREFIX = ("!")  
bot = commands.Bot(command_prefix=BOT_PREFIX)

client.run(os.getenv('TOKEN'))

甚至可以同时运行bot和客户端吗?如果可能的话,我将如何使用令牌运行这两个实例。

否,您正在尝试运行两个实例,一个仅具有意图,另一个作为没有意图的bot运行,您不需要单独的客户端和bot。只需使用一个:

BOT_前缀=! intents=discord.Intentsmembers=True,messages=True,guilds=True client=commands.Botcommand\u prefix=BOT\u prefix,intents=intents client.runos.getenv'TOKEN' 现在,您可以使用@client.command或@client.event定义命令或事件。若您更愿意使用bot,那个么将clienteverywhere更改为bot,但不要同时使用两者