【问题标题】:Discord selfbot pythonDiscord 自我机器人 python
【发布时间】: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

【问题讨论】:

  • 您不需要ClientBot。 (每个Bot 也是一个Client)。你可以去掉client = discord.Client()这一行。
  • 谢谢。也不知道为什么,但是我说 ayy 和机器人回答 lmao 的部分,坏了......

标签: python python-3.x bots discord discord.py


【解决方案1】:

我将第 25 行更改为:

await message.channel.send("lmao")

似乎现在可以工作了:)

【讨论】:

    【解决方案2】:

    做这个

    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, ctx):
        if message.content == "ayy":
            await ctx.send("lmao")
    
    b.run(TOKEN, bot = False)
    

    【讨论】:

    • 欢迎来到 SO @user14308313 我们很高兴您回答了一个老问题。您可以通过解释代码工作的原因以及答案的来源(如文档等)来改进您的答案。好的,再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 2021-07-20
    • 2021-07-17
    • 2019-01-12
    • 2019-05-10
    • 2021-07-24
    • 1970-01-01
    相关资源
    最近更新 更多