Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

python - running a token for two things

so I'm trying to create a bot for my dis server however two parts of my code requires the token to run them however no matter my efforts I have not been able to run both with the token.

my code:

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'))

is it even possible to run both the bot and the client? if possible how would i go about running them both with the token.

question from:https://stackoverflow.com/questions/65948773/running-a-token-for-two-things

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, you're attempting to run two instances, one with only intents and another as a bot without intents, you don't need a separate client and bot. Just use one:

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

client = commands.Bot(command_prefix = BOT_PREFIX, intents = intents)

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

Now you can define commands or events with @client.command or @client.event. If you'd rather use bot, then change client everywhere to bot, but don't use both.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...