$ python3 -m pip install -U 检查您正在使用的 discord.py 版本,一切已经准备就绪,让我们开始写机器人吧。如果它报 ModuleNotFoundError 或者 ImportError 那么您的 discord.py 安装有问题。bot = commands.Bot(command_prefix='$', description='A bot that greets the user back.')命令前缀是消息内容最...
创建一个名为bot.py的新文件,并将以下代码粘贴到其中: from discord import Intents from discord.ext import commands from dotenv import load_dotenv import os import replicate load_dotenv() intents = Intents.default() intents.message_content = True bot = commands.Bot( command_prefix="!", descrip...
import discord import os import random import praw from keep_alive import keep_alive from discord.ext import commands from discord.ext.commands import Bot import time client = commands.Bot(command_prefix='.') sec_triggers = ['just a sec', 'Just a sec', 'just a second', 'Just a secon...
确保你已经安装了discord.py库。你可以使用以下命令在Python中安装它: 确保你已经安装了discord.py库。你可以使用以下命令在Python中安装它: 导入所需的库和模块: 导入所需的库和模块: 创建一个bot对象和一个commands.Bot对象: 创建一个bot对象和一个commands.Bot对象: ...
使用命令| Discord bot(python获取用户的消息 discord.py 我正在编写一个非常简单的discord py bot命令,返回用户在说$send_back之后写的句子: @client.command() async def send_back(ctx,sentence): await ctx.send(sentence) 我想让我的机器人返回完整的句子,但问题是它只返回句子的第一个单词: 用户:$send...
if isinstance(error, commands.CommandOnCooldown): await ctx.send(f'This command is on cooldown. Please wait {error.retry_after:.2f} seconds.') bot.run('YOUR_BOT_TOKEN') 在上面的示例中,my_command命令被设置为每个用户在执行后需要等待60秒才能再次执行。如果用户在冷却时间内尝试执行该命令,将会...
Python ibeautiful 2023-12-12 10:00:08 因此,如果我实现了 bot.event,bot.command 就不起作用,但如果我评论或删除 bot.event,bot.command 就可以正常工作。在这里,bot.command 不起作用,但 bot.event 起作用:# bot.pyimport osfrom discord.ext import commandsfrom dotenv import load_dotenvload_dotenv()...
(无关小提琴)的闲聊, 摸爬滚打,把所有能踩的坑都踩了,终于成功通过 python 把 chatGPT bot (对话机器人) 添加到 Discord ,等于是把灵魂注入了天才画家(一个比喻,别较真)。 首先说下目的:单独的MJ和单独的G…
bot = discord.ext.commands.Bot(command_prefix = "your_prefix"); @client.event async def on_ready(): print('We have logged in as {0.user}'.format(client)) #自动回复? @client.event async def on_message(message): if message.author == client.user: ...
@bot.command() async def mycommand(ctx): async with ctx.typing(): # do expensive stuff here await asyncio.sleep(10) await ctx.send('done!') 旧版本使用这个: @bot.command(pass_context=True) async def longCommand(ctx): await bot.send_typing(ctx.channel) await asyncio.sleep(10) await...