【问题标题】:Discord bot not working. Cannot find a solution不和谐机器人不工作。找不到解决方案
【发布时间】:2021-04-02 07:14:12
【问题描述】:

我正在尝试根据我在 YouTube 上找到的视频制作 Discord 机器人。在视频中完成后,它似乎工作得很好,但我知道可能有什么问题。顺便说一句,这是一个大型 DMs 机器人

dmass.py

from discord.ext.commands import bot
from discord import game
from discord.ext import commands
import asyncio
import platform
import colorsys
import random
import time

client = commands.Bot(command_prefix = '+', case_insensitive=True)
Client = discord.client
Clientdiscord = discord.Client()

@client.event
async def on_ready():
    print('Logged in as '+client.user.name+' (ID:'+client.user.id+') | Connected to '+str(len(client.servers))+' servers | Connected to '+str(len(set(client.get_all_members())))+' users')
    print('--------')
    print('--------')
    print('CREATED AND HOSTED BY SUBHANKAR DAS')

@client.command(pass_context = True)
@commands.has_permissions(kick_members=True)     
async def userinfo(ctx, user: discord.Member):
    r, g, b = tuple(int(x * 255) for x in colorsys.hsv_to_rgb(random.random(), 1, 1))
    embed = discord.Embed(title="{}'s info".format(user.name), description="Here's what I could find.", color = discord.Color((r << 16) + (g << 8) + b))
    embed.add_field(name="Name", value=user.name, inline=True)
    embed.add_field(name="ID", value=user.id, inline=True)
    embed.add_field(name="Status", value=user.status, inline=True)
    embed.add_field(name="Highest role", value=user.top_role)
    embed.add_field(name="Joined", value=user.joined_at)
    embed.set_thumbnail(url=user.avatar_url)
    await client.say(embed=embed)
    
@commands.has_permissions(administrator=True)
@client.command(pass_context = True)
async def send(ctx, *, content: str):
        for member in ctx.message.server.members:
            try:
                await client.send_message(member, content)
                await client.say("DM Sent To : {} :white_check_mark:  ".format(member))
            except:
                print("can't")
                await client.say("DM can't Sent To : {} :x: ".format(member))


client.run("YOUR BOT'S TOKEN HERE") 

过程文件

worker: python dmass.py

Requirements.txt

discord.py==0.16.12
asyncio

【问题讨论】:

  • 顺便说一句,我在 Heroku 托管它
  • 欢迎来到 stackoverflow,常春藤。请创建一个minimal, reproducible example。请写下您遇到的确切错误。

标签: python discord


【解决方案1】:

我真的看不出这里的问题。您是否按照该教程一步一步进行操作? 检查是否一切正常。 顺便说一句,您是否正确地将机器人的令牌放在最后一行?也许这就是问题所在。 无论如何,我看不到这个问题的重点,什么不工作,无法启动或无法发送DM?

【讨论】:

    猜你喜欢
    • 2021-01-17
    • 1970-01-01
    • 2018-08-24
    • 2021-01-19
    • 2022-01-15
    • 2018-05-19
    • 2021-11-08
    • 2018-03-20
    • 2018-11-06
    相关资源
    最近更新 更多