当前位置: 代码迷 >> python >> 无法使用discord.py连接到主机
  详细解决方案

无法使用discord.py连接到主机

热度:97   发布时间:2023-07-14 08:45:55.0

我试图建立一个非常简单的机器人。 本质上是发送一条将由用户输入预定义的消息。 但是,我只是测试了所有内容,然后尽我所能。

我们已经构建了一个Slack机器人,并且效果很好。 我似乎在寻找最好的途径以发送简单的预告消息方面遇到问题。

我已经找到了一些教程,并在下面附上我应理解的代码。 但这并不是根据错误代码的意思进行连接。 '无法连接到主机discord app.com等

import discord
import asyncio
from discord.ext import commands

bot = commands.Bot(command_prefix='$', description='A bot that posts raffles.')


@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


@bot.command()
async def raffle(ctx):
    await ctx.send("Hello!")

bot.run('TOKEN')

如果您无法连接到主机,则很可能是您的IP被禁止(或您的服务器),这可能意味着以前使用您IP的人做了一些愚蠢的事情。 要获得禁止,您可能应该发送电子邮件至support@discordapp.com

另外,您是否尝试过在本地运行该机器人?