【发布时间】:2020-12-03 22:23:37
【问题描述】:
import datetime
import discord
from discord import message, ActivityType
from discord.ext import commands
import asyncio
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='.', intents=intents)
guild = 'SwiftNetwork'
time = datetime.date.today()
badword = ['bw', 'bw1', 'bw2', 'bw3']
@bot.event
async def on_ready():
print('Wir sind als {1} auf {0} eingeloggt Vers: {2}'.format(guild, bot.user.name, discord.__version__))
channel = bot.get_channel(id=697572461629407305)
await channel.send('Heute ist der {0}.{1}.{2}'.format(time.day, time.month, time.year))
# await bot.channel.send('Beep Boop Beep, Roboter Angriff wird gestartet..')
bot.loop.create_task(status_task())
@bot.command()
async def hello(ctx):
await ctx.channel.send(f"Hello! {ctx.author.mention}")
@bot.command()
async def ping(ctx):
await ctx.channel.send(round(bot.latency * 1000))
@bot.command()
async def poll(ctx, message, *args):
# print(len(args) + 1)
emoji = '1️⃣'
pollem = discord.Embed(title='', description=f'{message}')
context = []
reactionx = ['1️⃣', '2️⃣', '3️⃣', '4️⃣']
if len(args) >= 2:
for r in range(0, len(args), 2):
reaction = ['1️⃣', '2️⃣', '3️⃣', '4️⃣']
for x in range(1, len(args), 2):
context.append(args[x])
for a in range(0, len(args), 2):
pollem.add_field(name=' {1} {0}'.format(args[a], reaction[int(r / 2)]), value=context[int(a / 2)],
inline=False)
ms = await ctx.channel.send(embed=pollem)
else:
await ctx.channel.send('Check Args')
async def status_task():
async def status_task():
while True:
await bot.change_presence(activity=discord.Game('Hello'), status=discord.Status.online)
await asyncio.sleep(3)
await bot.change_presence(activity=discord.Game('Moin'), status=discord.Status.online)
await asyncio.sleep(3)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"), status=discord.Status.online)
await asyncio.sleep(3)
@bot.event
async def on_message(ctx):
if ctx.author.bot:
return
for word in ctx.content.split(' '):
if word in badword:
await ctx.delete()
问题出在最后一个事件中。
如果我这样运行它,ctx.delete() 将起作用,但上面的所有命令都不起作用。
如果我删除 @bot.event,命令会起作用,但 ctx.delete() 不会。
我想说我确定这是@bot.event 的原因,但在on_ready 我也在使用它并且它工作正常。
所以现在我真的没有在代码中看到任何问题。
【问题讨论】:
-
也许尝试在所有 @bot.command() async def 之前处理它(在 on_ready 之后),我实际上不知道为什么,但我没有看到任何不把它放在那里的机器人,并且可能有一个原因
-
我试过这个。结果相同,只有删除有效。
标签: python discord discord.py