【问题标题】:How to add a discord id/username如何添加不和谐的 ID/用户名
【发布时间】:2021-05-22 18:49:46
【问题描述】:

我想在代码中添加用户名或 ID,以便当我(或其他人)执行 .d @username 时,selfbot 会执行整个“.accept”和“u 4”响应。

代码:

import discord
import os
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

client = discord.Client()
b = Bot(command_prefix = ".d")

@b.event
async def on_ready():
    print("rdy")

@b.event
async def on_message(message)
    if message.content == ".d":
        await message.channel.send(".accept")
        await message.channel.send("u 4")

b.run(os.getenv("TOKEN"), bot = False)

【问题讨论】:

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


    【解决方案1】:

    你应该使用命令让事情变得更容易。

    @b.command(aliases=['.d'])
    async def d(ctx, member: discord.Member):
          await ctx.send(".accept")
          await ctx.send("u 4")
    

    我在别名中添加了 .d ,因为您不能拥有以 . 开头的函数。这是更多信息的链接。 https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=group#commands

    【讨论】:

    • 添加它代替第二个事件会返回以下错误:File "main.py", line 15 b.commands(aliases=['.d']) ^ SyntaxError: invalid syntax 我也有关于命令的问题。您提供的代码是否允许 selfbot 响应 .d @username ping 的任何成员,还是我必须输入我想要的用户名来代替某些东西?换句话说,它会回复我说 .d @123 和 .d @456,还是我必须输入我希望它回复的特定用户名?如果是后者,我会在哪里输入,我会在有或没有@的情况下这样做吗?
    • 为清楚起见,这是我的新代码:pastebin.com/N8cZpJHe
    • 对不起,我忘了加@。我已经相应地编辑了代码。无需添加事件。我不确定你到底在问什么。您能否详细说明您想要什么。
    • 我只是在问我是否可以在“.d”之后提及任何成员并让它响应,或者我是否必须指定一个特定的成员,但我想我现在明白了。我修复了删除事件并将 @ 添加到 b.commands,但现在出现以下错误:Traceback (most recent call last): File "main.py", line 14, in <module> @b.commands(aliases=['.d']) TypeError: 'set' object is not callable 我的代码再次:​​pastebin.com/N8cZpJHe
    猜你喜欢
    • 2019-08-06
    • 1970-01-01
    • 2019-05-09
    • 2020-10-09
    • 1970-01-01
    • 2019-05-31
    • 2017-09-18
    • 2019-04-14
    • 2020-05-25
    相关资源
    最近更新 更多