【发布时间】:2020-09-08 19:38:08
【问题描述】:
所以,我在 cogs 中制作了赠品代码,代码是:
import discord
import datetime
import time
import asyncio
import random
import random
from discord.ext import commands
from discord import Embed
class Giveaway(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def giveaway(self, ctx, time: int, *, prize):
giveawayembed = discord.Embed(
title="???? New Giveaway! ????",
colour=discord.Color.green()
)
giveawayembed.add_field(name="Prize", value="{}".format(prize), inline=False)
giveawayembed.add_field(name="Hosted by", value=f"{ctx.author.mention}", inline=False)
giveawayembed.add_field(name="Ends in", value="{}s".format(time))
msg = await ctx.send(embed=giveawayembed)
reactions = await msg.add_reaction("????")
await asyncio.sleep(time)
async for users in reactions.users(0):
users = await reaction.users().flatten()
winner = random.choice(users)
endembed = discord.Embed(
title="Giveaway ended!",
description="Prize: {}\nWinner: {}".format(prize, winner))
await msg.edit(embed=endembed)
@giveaway.error
async def giveaway_error(self, ctx, error):
await ctx.send(error)
print(error)
raise error
def setup(client):
client.add_cog(Giveaway(client))
但是当我尝试它时,在工作中,但获得获胜者有一些错误 错误:
discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“NoneType”对象没有“用户”属性
【问题讨论】:
标签: python discord.py discord.py-rewrite