[英]Message Will Not Send To Channel w/ Discord.py
我正在编写一个 discord 机器人,当有人使用命令防止滥用时,它会将嵌入发送到单独的频道,因此我们的管理员可以密切关注使用情况。
我有这个代码:
@client.command()
@has_permissions(manage_messages=True)
async def purge(ctx, amount=5):
await ctx.channel.purge(limit = amount + 1) # Plus one is so that it also deletes the players purge message
embed = discord.Embed(title="Purged Channel", description="", colour=0xe74c3c, timestamp=datetime.utcnow())
embed.set_author(name="CS Moderation", icon_url="https://cdn.discordapp.com/attachments/938857720268865546/938863881726615602/ca6.png")
embed.add_field(name="Staff Member", value=ctx.author.mention, inline=False)
embed.set_footer(text="Made by HeadOfTheBacons#6666", icon_url=None)
channel = client.get_channel("938898514656784404") #Change ID of logging channel if needed
await channel.send(embed = embed)
当我运行它时,我无法将嵌入发送到不同的频道。 我已经尝试过检查其他帖子,但我一点运气都没有。 当我使用命令或尝试运行机器人时,我没有错误。 这里的重点是当有人使用命令制作新的嵌入,设置首选项,指定我希望将此嵌入发送到的特定频道 ID,并让计算机将其发送到该频道。 但是,它不发送。 为什么我的代码不起作用? 我需要在我的代码中更改哪些内容才能发送消息?
检查您的程序中是否有on_command_error function,这可能是您没有错误问题的原因。
也不是 embed.footer 不能为 None,client.get_channel 需要 Integer。
所以你可以试试下面的代码,它应该可以工作:
from datetime import datetime
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
client = commands.Bot(command_prefix="prefix")
@client.command()
@has_permissions(manage_messages=True)
async def purge(ctx, amount=5):
await ctx.channel.purge(limit=amount + 1) # Plus one is so that it also deletes the players purge message
embed = discord.Embed(title="Purged Channel", description="", colour=0xe74c3c, timestamp=datetime.utcnow())
embed.set_author(name="CS Moderation", icon_url=client.user.avatar_url)
embed.add_field(name="Staff Member", value=ctx.author.mention, inline=False)
embed.set_footer(text="Made by HeadOfTheBacons#6666")
channel = client.get_channel(938898514656784404) # Change ID of logging channel if needed
await channel.send(embed=embed)
client.run("TOKEN")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.