树莓托管机器人

时间:2019-08-26 07:18:56

标签: python python-3.x discord.py-rewrite

我试图在树莓派上运行我的机器人,除非我不放置令牌,否则它将无法正常工作。在Windows上,我可以读取一个名为token.txt的文件,然后将“ client.run(token)”放入但树莓给我一个错误:错误4004身份验证失败

import discord
import os
import random
from random import choice
from discord.ext import commands


client = commands.Bot(command_prefix=".")
client.remove_command("help")

f = open("token.txt", "r")
token = f.read()


@client.command()
async def someone(ctx):
    try:
        await ctx.send(choice(tuple(member.mention for member in ctx.guild.members if not member.bot and member != ctx.author and member.status == discord.Status.online)))
    except IndexError:
        await ctx.send("You are the only human member on it!")

for filename in os.listdir("./cogs"):
    if filename.endswith(".py"):
        client.load_extension(f"cogs.{filename[:-3]}")

client.run(token)

这是它给出的错误: discord.errors.ConnectionClosed:WebSocket连接已关闭:代码= 4004(专用),原因=身份验证失败。

1 个答案:

答案 0 :(得分:1)

显然,没有正确读取token.txt。 解决了变化

client.run(token)

client.run(token.strip())