问另一个问题。这次更复杂(至少对我来说)。所以我在做一个不和谐机器人,当我做的时候,比如k!发货时,它会打印“a”(这是用于调试的),但不会显示嵌入。当我移除“madoka”和“神奇女孩”的关键词检测器时,evrey thing就没事了。我认为这个代码位就是问题所在。这是完整的代码。(但不是ofc的标记)夫妻名单上的名字也被删除了,没有朋友的名字,所以很有意义
# Imports
import discord
from discord.ext import commands
import random
# Credentials
TOKEN = 'use your imagination and imagine a token here :)'
# Create bot
client = commands.Bot(command_prefix='k!')
# Startup Information
@client.event
async def on_message(message):
if "madoka" in message.content:
await message.channel.send("✨being meguca is suffering✨")
@client.event
async def on_message(message):
if "magical girl" in message.content:
await message.channel.send("✨being meguca is suffering✨")
# Commands
@client.command()
async def jupiter(ctx):
await ctx.send('Peanut Butter')
# lists for commands
couple_list = ['imagination™']
ship_list = ['Madoka Kaname', 'Homura Akemi', 'Sayaka Miki', 'Mami Tomoe', 'Kyo(u)ko Sakura', 'Hitomi Shizuki',
'Kyosuke Kamijio']
ship_dis = ['It would be so intense!', 'A nail biter!', 'Its the best pick I got!']
# couple command
@client.command()
async def couple(ctx):
embed = discord.Embed(title=('In my opinion, ' + (random.choice(couple_list)) + ' and ' + (
random.choice(couple_list)) + ' would be a great pair!'), color=0x8b0000)
embed.set_footer(text="What a nice couple 💘💖💗💓🧡💝💙❤💕💔♥♥")
await ctx.send(embed=embed)
# ship command
@client.command()
async def ship(ctx):
ship_cmd = discord.Embed(title=('In my opinion, ' + (random.choice(ship_list)) + ' and ' + (
random.choice(ship_list)) + ' would be a great ship!'), color=0x8b0000)
ship_cmd.set_footer(text=(random.choice(ship_dis)))
ship_cmd.set_thumbnail(
url="https://cdn.discordapp.com/attachments/801105512933752882/845050099678576640/unknown.png")
await ctx.send(embed=ship_cmd)
print("a")
# status
@client.event
async def on_ready():
await client.change_presence(
activity=discord.Activity(type=discord.ActivityType.watching, name='TOO MANY NAGITO EDITS!!'))
client.run(TOKEN)
解决这个问题的任何帮助都将是巨大的! -杰克
你的错误很容易处理。实际上,您已经多次添加了
on_message
函数,这不是您的操作方式您可以使用
if
语句,因此可以通过将它们全部保存在一个函数中来使用它们例如:
我将执行两个任务,这两个任务都将在
on_message
中定义一次这就告诉你怎么做。但现在我们正在您的代码中实现它。因此,如果我们在一个函数中编译所有这些:
现在,这将帮助您正确地使用所有信息
但是现在,我看到您正在使用它,您也在创建
command()
,所以您必须知道一件事。如果您不添加process_command()
语句,那么您的命令将根本无法工作。你会一直试图找出错误,但你的朋友不会知道。所以我要说清楚当您试图将
event
与command()
一起使用时,以下语句非常重要现在,让我们将其添加到您的代码中
这肯定会帮助你纠正错误。如果您仍然有任何问题,请在评论中询问我的意见
谢谢D
相关问题 更多 >
编程相关推荐