【问题标题】:My Killswitch is not working in Discord.py and it's not working, no error message我的 Killswitch 无法在 Discord.py 中运行,也无法运行,没有错误消息
【发布时间】:2021-05-20 01:42:03
【问题描述】:

所以,我一直在 discord.py 中为我的机器人开发一个 killswitch,但我遇到了一个难题。我的终止开关不起作用,它没有给我一个错误。如果有人可以提供帮助,我将不胜感激。

import discord
from discord.ext import commands, tasks
from keep_alive import keep_alive
import asyncio
import random
import json
import random
import discord.utils
from datetime import datetime
client = commands.Bot(command_prefix=',')

client.remove_command('help')


@client.event
async def on_ready():
     global startdate
     startdate = datetime.now()
     await client.change_presence(
       status=discord.Status.online,
       activity=discord.Game('Type "," to activate me! e'))
     print('Bot is ready.')

@client.command(aliases=["shut", "shutdown", "quit", "stop_that", "stahp", "kill"])
@commands.has_permissions(administrator=True)
async def stop(ctx, member: discord.Member = None):
 embed = discord.Embed(colour=discord.Green())
 embed.add_field(name="I have been Killed", value=f"{member.name} has killed me! That's very unpog of them!", inline=False)
 embed.set_image(url="")
 embed.set_thumbnail(url="")
 embed.set_footer(text=f"Killed By: {ctx.author.name}")
 await ctx.send(embed=embed)
 await client.logout()

client.run('no token for you :)')

【问题讨论】:

  • 你试过client.close()吗?
  • 您是打算简单地以,shut,shut some_user 运行命令吗?
  • 感谢大家的支持!你帮我把终止开关做得更好了

标签: python discord discord.py repl.it


【解决方案1】:

我在您的代码中看到的第一件事是,当您定义嵌入时,您只定义了颜色。我继续添加标题和描述的其他字段并将它们设置为无

我看到的第二个问题是在添加字段值时,您调用了member.name 但是你应该打电话给member.display_name

最后两个问题是您定义了嵌入图像和缩略图,但是您没有传递任何值。相反,要么传递None,要么一开始就不定义它们

`

import discord
from discord.ext import commands, tasks
import asyncio
import random
import json
import random
import discord.utils
from datetime import datetime
client = commands.Bot(command_prefix=',')

client.remove_command('help')


@client.event
async def on_ready():
    global startdate
    startdate = datetime.now()
    await client.change_presence(
      status=discord.Status.online,
      activity=discord.Game('Type "," to activate me! e'))
    print('Bot is ready.')

@client.command(aliases=["shut", "shutdown", "quit", "stop_that", "stahp", "kill"])
@commands.has_permissions(administrator=True)
async def stop(ctx, member: discord.Member = None):
    embed = discord.Embed(title=None, description=None, color=0x00FF00)
    embed.add_field(name="I have been Killed", value=f"{member.display_name} has killed me! That's very unpog of them!", inline=False)
    embed.set_footer(text=f"Killed By: {ctx.author.name}")
    await ctx.send(embed=embed)
    await client.logout()

client.run('YOUR TOKEN HERE')

`

【讨论】:

  • 没有必要将嵌入字段初始化为无,如果你不给它们一个值,它们默认为空。 member.name 也没有错 - display_name 是别的东西,name 也存在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
  • 2018-09-24
  • 2021-03-31
  • 2016-07-08
  • 2018-08-23
  • 2023-04-10
  • 2022-08-11
相关资源
最近更新 更多