当我为它键入命令时,我的机器人不会发送随机 DM。
我的代码有什么不正确?
我不明白出了什么问题。
有什么问题吗
@client.command(pass_context=True)
async def meowzdm(ctx):
variable = [
"Hi im a bot and i wish you a good day!",
"Hi, my name is Meowzbot and i hope you sleep well tonight!",
"Hello, thanks for using this command, now i can tell you that you are a great human!"
"did you know: a person who uses this command is a very kind person!"]
await client.message.author.send(ctx.message.author.send, "{}".format(random.choice(variable)))
这是我的其余代码
import discord
import os
import time
import discord.ext
from discord.utils import get
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions, CheckFailure, check
import random
#^ basic imports for other features of discord.py and python ^
client = discord.Client()
client = commands.Bot(command_prefix='!') #put your own prefix here
@client.event
async def on_ready():
print ("bot online")
@client.command()
async def ping(ctx):
await ctx.send(
"pong"
) #simple command so that when you type "!ping" the bot will respond with "pong!"
@client.command()
async def pong(ctx):
await ctx.send("ping")
@client.command()
async def meow(ctx):
await ctx.send("woof")
@client.command()
async def woof(ctx):
await ctx.send("meow")
@client.command()
async def pizza(ctx):
await ctx.send(
"keanu's favourite pizza is bbq chicken gabriel's is BBQ meat lovers"
)
@client.command()
async def nicejob(ctx):
await ctx.send("well done! you did it! congrats now do more good stuff")
@client.command()
async def nevergonna(ctx):
await ctx.send("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
@client.command()
async def voicecrack(ctx):
await ctx.send("https://www.youtube.com/watch?v=BjDebmqFRuc")
@client.command()
async def botquestion(ctx):
await ctx.send(
"i have no idea why i was created other than that i can be used to tell stories and message funny things back to you"
)
@client.command()
async def highfive(ctx):
await ctx.send(
"highfive!"
)
@client.command()
async def coding(ctx):
await ctx.send("here is where i was coded from!: https://replit.com/~")
@client.command()
async def bruh(ctx):
await ctx.send("*bruh moment intensifies*")
@client.command()
async def commandlist(ctx):
await ctx.send(
"here is a list of my commands: ping, pong, meow, woof, pizza, nicejob, nevergonna, voicecrack, botquestion, highfive, coding, bruh, bothype, botdm, meowzmessage and of course, commandlist and cl. your welcome by the way. *P.S. commandlist and cl are the same command* *P.P.S. you need to use ! at the start of each command*"
)
@client.command()
async def cl(ctx):
await ctx.send(
"here is a list of my commands: ping, pong, meow, woof, pizza, nicejob, nevergonna, voicecrack, botquestion, highfive, coding, bruh, bothype, botdm, meowzmessage and of course, commandlist and cl. your welcome by the way. *P.S. commandlist and cl are the same command* *P.P.S. you need to use ! at the start of each command*"
)
@client.command()
async def bothype(ctx):
await ctx.send("LETS GO WE HAVE OUR OWN BOT! *that's me by the way!*")
@client.command()
async def botdm(ctx):
await ctx.message.author.send('hello im a bot and i am here to wish you a good day!')
@client.command(pass_context=True)
async def meowzdm(ctx):
variable = [
"Hi im a bot and i wish you a good day!",
"Hi, my name is Meowzbot and i hope you sleep well tonight!",
"Hello, thanks for using this command, now i can tell you that you are a great human!"
"did you know: a person who uses this command is a very kind person!"]
await client.message.author.send(ctx.message.author.send, "{}".format(random.choice(variable)))
client.run(os.getenv("TOKEN"))
答案 0 :(得分:0)
我可以看到几个问题。首先在您的原始问题中:
await client.message.author.send(ctx.message.author.send, "{}".format(random.choice(variable)))
应该
await ctx.message.author.send("{}".format(random.choice(variable)))
然后在你的完整代码中也有这部分:
client = discord.Client()
client = commands.Bot(command_prefix='!')
您将 discord.Client
和 commands.Bot
对象以相同的名称命名
你可以通过改变来解决这个问题
client = commands.Bot(command_prefix='!')
到
bot = commands.Bot(command_prefix='!')
然后将装饰器中的 client.command
调用替换为 bot.command