简体   繁体   English

消息不会发送到带有 Discord.py 的通道

[英]Message Will Not Send To Channel w/ Discord.py

I am programming a discord bot that will send an embed to a separate channel when someone uses a command to prevent abuse and so our admins can keep an eye on usage.我正在编写一个 discord 机器人,当有人使用命令防止滥用时,它会将嵌入发送到单独的频道,因此我们的管理员可以密切关注使用情况。

I have this code:我有这个代码:

@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)

When I run this, I cannot get the embed to be sent to a different channel.当我运行它时,我无法将嵌入发送到不同的频道。 I have tried checking other posts already but I have not had much luck at all.我已经尝试过检查其他帖子,但我一点运气都没有。 I have no errors when I use the command or try to run the bot.当我使用命令或尝试运行机器人时,我没有错误。 The point here is when someone uses the command to make a new embed, set up the preferences, specify the specific channel ID where I want this embed to be sent to, and have the computer send it off to that channel.这里的重点是当有人使用命令制作新的嵌入,设置首选项,指定我希望将此嵌入发送到的特定频道 ID,并让计算机将其发送到该频道。 However, it is not sending.但是,它不发送。 Why is my code not working?为什么我的代码不起作用? What do I need to change in my code to make this send a message?我需要在我的代码中更改哪些内容才能发送消息?

Check if you have an on_command_error function in your program, it could be the reason of your no error problem.检查您的程序中是否有on_command_error function,这可能是您没有错误问题的原因。

Also not that the embed.footer can't be None, and the client.get_channel requires an Integer.也不是 embed.footer 不能为 None,client.get_channel 需要 Integer。

So you can try out the following code, it should work:所以你可以试试下面的代码,它应该可以工作:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM