【问题标题】:Discord.py not showing outputDiscord.py 不显示输出
【发布时间】:2021-02-03 00:34:02
【问题描述】:

所以,我是 discord.py 的新手,我最近正在制作我的新机器人。我做了一个硬币翻转命令,但由于某种原因它不起作用。它根本没有显示任何输出。它也没有在控制台中显示任何类型的错误。这是我的代码:

import discord
from discord.ext import commands

import random
import time

client= commands.Bot(command_prefix="ak!")

@client.event

async def on_ready():
    print("Bot is ready")


@client.command()

async def coinflip(ctx):
    
    action= random.randint(0, 1)
    if(action == 0):
        flip= "Tails"
    elif(action == 1):
        flip= "Heads"

    time.sleep(1)
    embed= discord.Embed(title=f"{ctx.author.name} has flipped the coin!", description=f"{flip} it is!")
    await ctx.send(embed=embed)



client.run("token")

我不知道我做错了什么。

【问题讨论】:

  • 这就是你的机器人吗?
  • 是的,就是这样。
  • 你试过答案中的代码了吗?

标签: python discord bots discord.py


【解决方案1】:

discord.py 1.5.1 上有一个意图更新 所以试着像这样定义机器人:

from discord import Intents
from discord.ext.commands import Bot

intent = Intents().all()

bot = Bot(command_prefix='prefix', intents=intent)

... # Some code under this line

【讨论】:

    猜你喜欢
    • 2021-11-10
    • 2021-07-02
    • 2020-03-16
    • 2014-04-30
    • 2019-09-19
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多