【发布时间】:2019-08-10 17:16:56
【问题描述】:
我正在为我与一些 irl 朋友一起操作的服务器制作一个 selfbot。 Atm 我有点卡住了,不知道如何修复我的 python 代码。 当我说“ayy”时机器人应该说“lmao”,当我说“lmao”时应该说“ayy” 只是一些有趣的东西:) 如果可能的话,我希望 selfbot 只回复我而不回复其他人。
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
#TOKEN
TOKEN = "Token goes here"
client = discord.Client()
b = Bot(command_prefix = "ayy")
@b.event
async def on_ready():
print("ayy lmao")
@b.event
async def on_message(message):
if message.content == "ayy":
away.b.send_message(message.channel, "lmao")
b.run(TOKEN, bot = False)
错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\FoxMaccloud\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "F:\Python\Random\Discord_bot\BetterBakaBot2.py", line 25, in on_message
NameError: name 'away' is not defined
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\FoxMaccloud\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "F:\Python\Random\Discord_bot\BetterBakaBot2.py", line 25, in on_message
NameError: name 'away' is not defined
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\FoxMaccloud\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "F:\Python\Random\Discord_bot\BetterBakaBot2.py", line 24, in on_message
away.b.send_message(message.channel, "lmao")
NameError: name 'away' is not defined
【问题讨论】:
-
您不需要
Client和Bot。 (每个Bot也是一个Client)。你可以去掉client = discord.Client()这一行。 -
谢谢。也不知道为什么,但是我说 ayy 和机器人回答 lmao 的部分,坏了......
标签: python python-3.x bots discord discord.py